Пример #1
0
        /// <summary>
        /// Change the selection to be the specified SnapshotSpan value and update the caret to be on the
        /// last included point in the SnapshotSpan.
        /// </summary>
        public static void SelectAndMoveCaret(this ITextView textView, SnapshotSpan span)
        {
            var characterSpan   = CharacterSpan.CreateForSpan(span);
            var visualSelection = VisualSelection.CreateForward(VisualSpan.NewCharacter(characterSpan));

            visualSelection.SelectAndMoveCaret(textView);
        }
Пример #2
0
        public void Last_ZeroLength()
        {
            Create("cats", "dogs");
            var characterSpan = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(0, 0));

            Assert.False(characterSpan.Last.IsSome());
        }
Пример #3
0
        /// <summary>
        /// Change the selection to be the specified SnapshotSpan value and update the caret to be on the
        /// last included point in the SnapshotSpan.
        /// </summary>
        public static void SelectAndUpdateCaret(this ITextView textView, SnapshotSpan span)
        {
            var characterSpan = CharacterSpan.CreateForSpan(span);

            CommonUtil.SelectAndUpdateCaret(
                textView,
                VisualSelection.CreateForVisualSpan(VisualSpan.NewCharacter(characterSpan)));
        }
Пример #4
0
        public void Last_Simple()
        {
            Create("cats", "dogs");
            var characterSpan = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(0, 3));

            Assert.True(characterSpan.Last.IsSome());
            Assert.Equal('t', characterSpan.Last.Value.GetChar());
        }
Пример #5
0
        public void AdjustForSelectionKind_Character_Forward()
        {
            Create("cat dog bear");
            var characterSpan   = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(0, 4));
            var visualSpan      = VisualSpan.NewCharacter(characterSpan);
            var visualSelection = VisualSelection.CreateForward(visualSpan);

            Assert.Equal("cat", visualSelection.AdjustForSelectionKind(SelectionKind.Exclusive).VisualSpan.EditSpan.OverarchingSpan.GetText());
        }
Пример #6
0
        public void GetCaretPoint_Character_Backward()
        {
            Create("cats", "dogs");
            var visualSelection = VisualSelection.NewCharacter(
                CharacterSpan.CreateForSpan(_textBuffer.GetSpan(0, 2)),
                Path.Backward);

            Assert.Equal(_textBuffer.GetPoint(0), visualSelection.GetCaretPoint(SelectionKind.Inclusive));
        }
Пример #7
0
        public void CaretPoint_Character_Backward()
        {
            Create("cats", "dogs");
            var visualSelection = VisualSelection.NewCharacter(
                CharacterSpan.CreateForSpan(_textBuffer.GetSpan(0, 2)),
                false);

            Assert.AreEqual(_textBuffer.GetPoint(0), visualSelection.CaretPoint);
        }
Пример #8
0
        public void Select_Character_Forwards()
        {
            Create("big dog", "big cat", "big tree", "big fish");
            var characterSpan = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(1, 3));
            var visualSpan    = VisualSpan.NewCharacter(characterSpan);

            visualSpan.Select(_textView, Path.Forward);
            Assert.False(_textView.Selection.IsReversed);
            Assert.Equal(characterSpan.Span, _textView.GetSelectionSpan());
        }
Пример #9
0
        public void Create_LastLineLengthOfOne()
        {
            Create("cat", "dog", "fish");
            var endPoint      = _textBuffer.GetLine(1).Start.Add(1);
            var span          = new SnapshotSpan(_textBuffer.GetPoint(0), endPoint);
            var characterSpan = CharacterSpan.CreateForSpan(span);

            Assert.Equal(endPoint, characterSpan.End);
            Assert.Equal(2, characterSpan.LineCount);
        }
Пример #10
0
        private void EnterMode(SnapshotSpan span)
        {
            var characterSpan   = CharacterSpan.CreateForSpan(span);
            var visualSelection = VisualSelection.NewCharacter(characterSpan, true);

            CommonUtil.SelectAndUpdateCaret(_textView, visualSelection);
            Assert.IsFalse(_context.IsEmpty);
            _context.RunAll();
            Assert.IsTrue(_context.IsEmpty);
        }
Пример #11
0
        public void Create_LastLineEmpty()
        {
            Create("cat", "", "dog");
            var endPoint      = _textBuffer.GetLine(1).End.Add(1);
            var span          = new SnapshotSpan(_textBuffer.GetPoint(0), endPoint);
            var characterSpan = CharacterSpan.CreateForSpan(span);

            Assert.Equal(endPoint, characterSpan.End);

            // The last line is included even though it's blank
            Assert.Equal(2, characterSpan.LineCount);
        }
Пример #12
0
        public void BackAndForth_Character_SingleLine()
        {
            Create("cats", "dogs");
            var characterSpan = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(1, 2));
            var all           = new[] { Path.Forward, Path.Backward };

            foreach (var path in all)
            {
                var visualSelection = VisualSelection.NewCharacter(characterSpan, path);
                visualSelection.SelectAndMoveCaret(_textView);
                var currentVisualSelection = VisualSelection.CreateForSelection(_textView, VisualKind.Character, SelectionKind.Inclusive);
                Assert.Equal(visualSelection, currentVisualSelection);
            }
        }
Пример #13
0
        public void BackAndForth_Character_SingleLine()
        {
            Create("cats", "dogs");
            var characterSpan = CharacterSpan.CreateForSpan(_textBuffer.GetSpan(1, 2));
            var all           = new[] { true, false };

            foreach (var isForward in all)
            {
                var visualSelection = VisualSelection.NewCharacter(characterSpan, isForward);
                CommonUtil.SelectAndUpdateCaret(_textView, visualSelection);
                var currentVisualSelection = VisualSelection.CreateForSelection(_textView, VisualKind.Character);
                Assert.AreEqual(visualSelection, currentVisualSelection);
            }
        }
Пример #14
0
 internal static VisualSpan CreateVisualSpanCharacter(SnapshotSpan span)
 {
     return(VisualSpan.NewCharacter(CharacterSpan.CreateForSpan(span)));
 }