/// <summary>
 /// Internal for testing purposes. All real caret positioning logic takes place here. <see cref="PositionCaretForEditing"/>
 /// only extracts the <paramref name="endLineText"/> and <paramref name="point"/> from the provided <see cref="ITextView"/>.
 /// Tests can call this method directly to avoid producing an IVsTextLines.
 /// </summary>
 /// <param name="endLineText"></param>
 /// <param name="point"></param>
 internal void PositionCaretForEditingInternal(string endLineText, SnapshotPoint point)
 {
     if (_indentCaretOnCommit && endLineText == string.Empty)
     {
         ITextViewExtensions.TryMoveCaretToAndEnsureVisible(TextView, new VirtualSnapshotPoint(point, _indentDepth));
     }
 }
示例#2
0
        public void ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandExecutionContext context)
        {
            HandlePossibleTypingCommand(args, nextHandler, span =>
            {
                var spans = new NormalizedSnapshotSpanCollection(
                    _renameService.ActiveSession.GetBufferManager(args.SubjectBuffer)
                    .GetEditableSpansForSnapshot(args.SubjectBuffer.CurrentSnapshot));

                for (var i = 0; i < spans.Count; i++)
                {
                    if (span == spans[i])
                    {
                        var selectNext   = i < spans.Count - 1 ? i + 1 : 0;
                        var newSelection = spans[selectNext];
                        ITextViewExtensions.TryMoveCaretToAndEnsureVisible(args.TextView, newSelection.Start);
                        args.TextView.SetSelection(newSelection);
                        break;
                    }
                }
            });
        }
            private void RestoreCaretPositions()
            {
                if (_caretChanged)
                {
                    return;
                }

                foreach (var tuple in _caretPositions)
                {
                    var position = tuple.Item1.GetCaretPoint(_subjectBuffer);
                    if (position != null)
                    {
                        var view = tuple.Item1;

                        if (!view.IsClosed)
                        {
                            ITextViewExtensions.TryMoveCaretToAndEnsureVisible(view, position.Value);
                        }
                    }
                }
            }