public void NavigateTo() { IWpfTextView wpfTextView = TextView as IWpfTextView; if (wpfTextView != null) { wpfTextView.VisualElement.Dispatcher.BeginInvoke((Action)(() => { TextView.Caret.MoveTo(SnapshotSpan.Start); TextView.Selection.Select(SnapshotSpan, false); TextView.ViewScroller.EnsureSpanVisible(SnapshotSpan, EnsureSpanVisibleOptions.ShowStart); Keyboard.Focus(wpfTextView.VisualElement); }), null); } }
public int OnItemChosen(int iCombo, int iIndex) { if (!ValidateIndex(iCombo, iIndex)) { return(VSConstants.E_INVALIDARG); } if (Updating) { return(VSConstants.E_FAIL); } try { IEditorNavigationTarget target = _navigationControls[iCombo].Item2[iIndex]; if (target != null) { // show the span, then adjust if necessary to make sure the seek portion is visible var span = MapTo(target.Span, _currentTextView.TextSnapshot, SpanTrackingMode.EdgeInclusive); _currentTextView.ViewScroller.EnsureSpanVisible(span, EnsureSpanVisibleOptions.AlwaysCenter | EnsureSpanVisibleOptions.ShowStart); var seek = target.Seek.Snapshot == null ? target.Span : target.Seek; seek = MapTo(seek, _currentTextView.TextSnapshot, SpanTrackingMode.EdgeInclusive); _currentTextView.Caret.MoveTo(seek.Start); _currentTextView.Selection.Select(seek, false); _currentTextView.ViewScroller.EnsureSpanVisible(seek, EnsureSpanVisibleOptions.MinimumScroll | EnsureSpanVisibleOptions.ShowStart); Keyboard.Focus(_currentTextView.VisualElement); } } catch (Exception ex) { if (ex.IsCritical()) { throw; } return(Marshal.GetHRForException(ex)); } return(VSConstants.S_OK); }