private static void RemoveSpan(HashSet <int> chars, CharacterSpan span)
 {
     for (var i = span.Start; i <= span.End; i++)
     {
         chars.Remove(i);
     }
 }
예제 #2
0
            public void UpToLineBreak()
            {
                Create("cat", "", "dog");
                var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), 1, 3);

                Assert.False(characterSpan.IncludeLastLineLineBreak);
            }
예제 #3
0
                public void AtLineBreak()
                {
                    Create("cat", "", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetLine(0).Start, 1, 3);

                    Assert.Equal(3, characterSpan.LastLinePositionCount);
                }
예제 #4
0
            public void EndOfNonEmptyLine()
            {
                Create("cat", "", "dog");
                var characterSpan = new CharacterSpan(_textBuffer.GetPoint(2), 1, 2);

                Assert.True(characterSpan.IncludeLastLineLineBreak);
            }
예제 #5
0
 public void SingleLineWhichIsEmpty()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetLine(1).Start, 1, 0);
     Assert.Equal(2, characterSpan.Length);
     Assert.Equal(2, characterSpan.LastLineLength);
 }
예제 #6
0
                public void IntoLineBreak()
                {
                    Create("cat", "", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), _textBuffer.GetPoint(4));

                    Assert.Equal(5, characterSpan.LastLineLength);
                }
예제 #7
0
        public void GetCommandStatusVisualCharacterMode()
        {
            string[] lines      = { "cat", "dog", "fish" };
            var      textBuffer = CreateTextBuffer(lines);

            _vimBuffer.TextBufferImpl = textBuffer;
            _vimBuffer.ModeImpl       = _visualMode.Object;
            _vimBuffer.ModeKindImpl   = ModeKind.VisualCharacter;

            // span1 selection is within one line, so the display should be the selected character count
            var span1      = new CharacterSpan(textBuffer.GetPointInLine(1, 1), textBuffer.GetPointInLine(1, 3));
            var selection1 = new VisualSelection.Character(span1, SearchPath.Forward);

            _visualMode.SetupGet(x => x.VisualSelection).Returns(selection1);
            Assert.Equal("2", CommandMarginUtil.GetShowCommandText(_vimBuffer));

            // span2 selection is over two lines, so the the display should be the selected line count
            var span2      = new CharacterSpan(textBuffer.GetPointInLine(0, 1), textBuffer.GetPointInLine(1, 2));
            var selection2 = new VisualSelection.Character(span2, SearchPath.Forward);

            _visualMode.SetupGet(x => x.VisualSelection).Returns(selection2);
            Assert.Equal("2", CommandMarginUtil.GetShowCommandText(_vimBuffer));

            // span3 selection is within one line and includes the CRLF at the end of the line, so the the display should be the length of the line + 1
            var span3      = new CharacterSpan(textBuffer.GetPointInLine(1, 1), textBuffer.GetPointInLine(1, lines[1].Length + 2));
            var selection3 = new VisualSelection.Character(span3, SearchPath.Forward);

            _visualMode.SetupGet(x => x.VisualSelection).Returns(selection3);
            Assert.Equal("3", CommandMarginUtil.GetShowCommandText(_vimBuffer));
        }
예제 #8
0
                public void IntoLineBreakDeep()
                {
                    Create("cat", "", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetLine(0).Start, 1, 5);

                    Assert.Equal(5, characterSpan.LastLineLength);
                }
예제 #9
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   = new CharacterSpan(span);
            var visualSelection = VisualSelection.CreateForward(VisualSpan.NewCharacter(characterSpan));

            visualSelection.SelectAndMoveCaret(textView);
        }
예제 #10
0
        public void End_SingleLine()
        {
            Create("cats", "dog");
            var characterSpan = new CharacterSpan(_textBuffer.GetPoint(1), 1, 2);

            Assert.AreEqual("at", characterSpan.Span.GetText());
        }
예제 #11
0
        public void End_MultiLine()
        {
            Create("cats", "dogs");
            var characterSpan = new CharacterSpan(_textBuffer.GetPoint(1), 2, 2);

            Assert.AreEqual("ats" + Environment.NewLine + "do", characterSpan.Span.GetText());
        }
예제 #12
0
            public void EmptyLine()
            {
                Create("cat", "", "dog");
                var characterSpan = new CharacterSpan(_textBuffer.GetLine(1).Start, 1, 0);

                Assert.False(characterSpan.IncludeLastLineLineBreak);
            }
예제 #13
0
            public void Last_ZeroLength()
            {
                Create("cats", "dogs");
                var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 0));

                Assert.False(characterSpan.Last.IsSome());
            }
        private static void ParseElement(XmlTextReader reader, Container parent, CharacterPositionFinder finder, IXmlFlavor flavor)
        {
            var name    = flavor.GetName(reader);
            var type    = flavor.GetType(reader);
            var content = flavor.GetContent(reader);

            var container = new Container
            {
                Type    = type,
                Name    = name,
                Content = content,
            };

            var isEmpty = reader.IsEmptyElement;

            var startingSpan = GetLocationSpanWithParseAttributes(reader, container, finder, flavor);
            var headerSpan   = GetCharacterSpan(startingSpan, finder);

            if (isEmpty)
            {
                // there is no content, so we have to get away of the footer by just using the '/>' characters as footer
                var headerSpanCorrected = new CharacterSpan(headerSpan.Start, Math.Max(headerSpan.Start, headerSpan.End - 2));
                var footerSpanCorrected = new CharacterSpan(Math.Max(0, headerSpan.End - 1), headerSpan.End);

                container.LocationSpan = startingSpan;
                container.HeaderSpan   = headerSpanCorrected;
                container.FooterSpan   = footerSpanCorrected;
            }
            else
            {
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    Parse(reader, container, finder, flavor);

                    // we had a side effect (reading further on stream to get the location span), so we have to check whether we found already an element or end element
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }

                var endingSpan = GetLocationSpan(reader);
                var footerSpan = GetCharacterSpan(endingSpan, finder);

                container.LocationSpan = new LocationSpan(startingSpan.Start, endingSpan.End);
                container.HeaderSpan   = headerSpan;
                container.FooterSpan   = footerSpan;
            }

            // check whether we can use a terminal node instead
            var child = flavor.FinalAdjustAfterParsingComplete(container);

            parent.Children.Add(child);
        }
예제 #15
0
            public void Last_Simple()
            {
                Create("cats", "dogs");
                var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 3));

                Assert.True(characterSpan.Last.IsSome());
                Assert.Equal('t', characterSpan.Last.Value.GetChar());
            }
예제 #16
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)));
        }
예제 #17
0
                public void SingleLineWhichIsEmpty()
                {
                    Create("cat", "", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetLine(1).Start, 1, 0);

                    Assert.Equal(0, characterSpan.Length);
                    Assert.Equal(0, characterSpan.LastLineLength);
                }
예제 #18
0
 public void Character_Forward()
 {
     Create("cat dog bear");
     var characterSpan = new CharacterSpan(_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());
 }
예제 #19
0
 public void LastLineEmpty()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), 2, 0);
     Assert.Equal(2, characterSpan.LineCount);
     Assert.Equal(2, characterSpan.LastLineLength);
     Assert.Equal(_textBuffer.GetLine(2).Start, characterSpan.End);
 }
예제 #20
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));
        }
예제 #21
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);
        }
예제 #22
0
                public void LastLineEmpty()
                {
                    Create("cat", "", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), 2, 0);

                    Assert.Equal(2, characterSpan.LineCount);
                    Assert.Equal(0, characterSpan.LastLineLength);
                    Assert.Equal(_textBuffer.GetLine(1).Start, characterSpan.End);
                }
예제 #23
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());
        }
예제 #24
0
                public void LongLastLinePositionCount()
                {
                    Create("cat", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), lineCount: 1, lastLineMaxPositionCount: 100);

                    Assert.Equal(1, characterSpan.LineCount);
                    Assert.Equal(5, characterSpan.LastLinePositionCount);
                    Assert.Equal(100, characterSpan.LastLineMaxPositionCount);
                }
예제 #25
0
 protected void EnterMode(SnapshotSpan span)
 {
     var characterSpan = new CharacterSpan(span);
     var visualSelection = VisualSelection.NewCharacter(characterSpan, Path.Forward);
     visualSelection.SelectAndMoveCaret(_textView);
     Assert.False(_context.IsEmpty);
     _context.RunAll();
     Assert.True(_context.IsEmpty);
 }
예제 #26
0
                public void IncludeLineBreakNextLineEmpty()
                {
                    Create("cat", "", "dog");
                    var span          = _textBuffer.GetLine(0).ExtentIncludingLineBreak;
                    var characterSpan = new CharacterSpan(span);

                    Assert.Equal(1, characterSpan.LineCount);
                    Assert.Equal(span, characterSpan.Span);
                }
예제 #27
0
                public void Forward()
                {
                    Create("big dog", "big cat", "big tree", "big fish");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(1, 3));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    Assert.False(_textView.Selection.IsReversed);
                    Assert.Equal(characterSpan.Span, _textView.GetSelectionSpan());
                }
예제 #28
0
                public void ForwardIntoLineBreak()
                {
                    Create("cat", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 4));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    Assert.Equal(4, _textView.Selection.StreamSelectionSpan.Length);
                    Assert.False(_textView.Selection.IsReversed);
                }
예제 #29
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);
        }
예제 #30
0
        public void Select_Character_Backwards()
        {
            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.Backward);
            Assert.True(_textView.Selection.IsReversed);
            Assert.Equal(characterSpan.Span, _textView.GetSelectionSpan());
        }
예제 #31
0
                public void LastLineLengthOfOne()
                {
                    Create("cat", "dog", "fish");
                    var endPoint      = _textBuffer.GetLine(1).Start.Add(1);
                    var span          = new SnapshotSpan(_textBuffer.GetPoint(0), endPoint);
                    var characterSpan = new CharacterSpan(span);

                    Assert.Equal(endPoint, characterSpan.End);
                    Assert.Equal(2, characterSpan.LineCount);
                }
예제 #32
0
            public void NegativeLastLineOffset1()
            {
                var textBuffer    = CreateTextBuffer("cat", "dog");
                var characterSpan = new CharacterSpan(
                    textBuffer.GetPointInLine(line: 0, column: 2),
                    textBuffer.GetPointInLine(line: 1, column: 1));
                var sel = StoredVisualSelection.CreateFromVisualSpan(VisualSpan.NewCharacter(characterSpan));

                Assert.Equal(StoredVisualSelection.NewCharacterLine(lineCount: 2, lastLineMaxOffset: -2), sel);
            }
예제 #33
0
                public void Backward()
                {
                    Create("big dog", "big cat", "big tree", "big fish");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(1, 3));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Backward);
                    TestableSynchronizationContext.RunAll();
                    Assert.True(_textView.Selection.IsReversed);
                    Assert.Equal(characterSpan.Span, _textView.GetSelectionSpan());
                }
예제 #34
0
                public void BackwardIntoLineBreak()
                {
                    Create("cat", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 4));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Backward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(4, _textView.Selection.StreamSelectionSpan.Length);
                    Assert.True(_textView.Selection.IsReversed);
                }
예제 #35
0
                public void LastLineEmpty()
                {
                    Create("cat", "", "dog");
                    var endPoint = _textBuffer.GetLine(1).End.Add(1);
                    var span = new SnapshotSpan(_textBuffer.GetPoint(0), endPoint);
                    var characterSpan = new CharacterSpan(span);
                    Assert.Equal(characterSpan.End, _textBuffer.GetLine(1).EndIncludingLineBreak);

                    // The last line is included even though it's blank
                    Assert.Equal(2, characterSpan.LineCount);
                    Assert.Equal(2, characterSpan.LastLineLength);
                }
예제 #36
0
 public void SingleLine()
 {
     Create("cats", "dogs");
     var characterSpan = new CharacterSpan(_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, tabStop: 4);
         Assert.Equal(visualSelection, currentVisualSelection);
     }
 }
예제 #37
0
 public void BackAndForth_Character_MultiLine()
 {
     Create("cats", "dogs", "fish");
     var characterSpan = new CharacterSpan(_textView.GetLine(0).Start, 2, 4);
     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);
     }
 }
예제 #38
0
 public void BackAndForth_Character_MultiLine()
 {
     Create("cats", "dogs", "fish");
     var characterSpan = new CharacterSpan(_textView.GetLine(0).Start, 2, 4);
     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.AreEqual(visualSelection, currentVisualSelection);
     }
 }
예제 #39
0
 public void End_SingleLine()
 {
     Create("cats", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetPoint(1), 1, 2);
     Assert.AreEqual("at", characterSpan.Span.GetText());
 }
예제 #40
0
 public void End_MultiLine()
 {
     Create("cats", "dogs");
     var characterSpan = new CharacterSpan(_textBuffer.GetPoint(1), 2, 2);
     Assert.AreEqual("ats" + Environment.NewLine + "do", characterSpan.Span.GetText());
 }
예제 #41
0
 public void ForwardIntoLineBreak()
 {
     Create("cat", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 4));
     var visualSpan = VisualSpan.NewCharacter(characterSpan);
     visualSpan.Select(_textView, Path.Forward);
     Assert.Equal(4, _textView.Selection.StreamSelectionSpan.Length);
     Assert.False(_textView.Selection.IsReversed);
 }
예제 #42
0
 public void Forward()
 {
     Create("big dog", "big cat", "big tree", "big fish");
     var characterSpan = new CharacterSpan(_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());
 }
예제 #43
0
 public void IntoLineBreakDeep()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetLine(0).Start, 0, 5);
     Assert.Equal(3, characterSpan.LastLineLength);
 }
예제 #44
0
 public void Last_ZeroLength()
 {
     Create("cats", "dogs");
     var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 0));
     Assert.False(characterSpan.Last.IsSome());
 }
예제 #45
0
            public void CalculateVisualSpan_CharacterBackAndForth()
            {
                Create("the dog kicked the ball", "into the tree");

                Action<SnapshotSpan> action = span =>
                {
                    var characterSpan = new CharacterSpan(span);
                    var visual = VisualSpan.NewCharacter(characterSpan);
                    var stored = StoredVisualSpan.OfVisualSpan(visual);
                    var restored = _commandUtil.CalculateVisualSpan(stored);
                    Assert.Equal(visual, restored);
                };

                action(new SnapshotSpan(_textView.TextSnapshot, 0, 3));
                action(new SnapshotSpan(_textView.TextSnapshot, 0, 4));
                action(new SnapshotSpan(_textView.GetLine(0).Start, _textView.GetLine(1).Start.Add(1)));
            }
예제 #46
0
 public void LastLineLengthOfOne()
 {
     Create("cat", "dog", "fish");
     var endPoint = _textBuffer.GetLine(1).Start.Add(1);
     var span = new SnapshotSpan(_textBuffer.GetPoint(0), endPoint);
     var characterSpan = new CharacterSpan(span);
     Assert.Equal(endPoint, characterSpan.End);
     Assert.Equal(2, characterSpan.LineCount);
 }
예제 #47
0
 public void EmptyLine()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetLine(1).Start, 1, 0);
     Assert.True(characterSpan.IncludeLastLineLineBreak);
 }
예제 #48
0
 public void EndOfNonEmptyLine()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetPoint(2), 1, 2);
     Assert.True(characterSpan.IncludeLastLineLineBreak);
 }
예제 #49
0
 public void UpToLineBreak()
 {
     Create("cat", "", "dog");
     var characterSpan = new CharacterSpan(_textBuffer.GetPoint(0), 1, 3);
     Assert.False(characterSpan.IncludeLastLineLineBreak);
 }
예제 #50
0
            public void EmptyLineDifferentiationTest()
            {
                Create("dog", "", "cat");
                var span1 = new CharacterSpan(_textBuffer.GetPoint(0), 1, 5);
                Assert.Equal(1, span1.LineCount);
                Assert.Equal(3, span1.LastLine.Length);

                var span2 = new CharacterSpan(_textBuffer.GetPoint(0), 2, 0);
                Assert.Equal(2, span2.LineCount);
                Assert.Equal(0, span2.LastLine.Length);

                Assert.NotEqual(span1, span2);
            }
예제 #51
0
 /// <summary>
 /// Switches mode, then sets the visual selection. The order is reversed from EnterMode(ModeKind, SnapshotSpan).
 /// </summary>
 /// <param name="kind"></param>
 /// <param name="span"></param>
 protected void SwitchEnterMode(ModeKind kind, SnapshotSpan span)
 {
     _vimBuffer.SwitchMode(kind, ModeArgument.None);
     var characterSpan = new CharacterSpan(span);
     var visualSelection = VisualSelection.NewCharacter(characterSpan, SearchPath.Forward);
     visualSelection.SelectAndMoveCaret(_textView);
     // skipping check: context.IsEmpty == false
     _context.RunAll();
     Assert.True(_context.IsEmpty);
 }
예제 #52
0
 public void Last_Simple()
 {
     Create("cats", "dogs");
     var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 3));
     Assert.True(characterSpan.Last.IsSome());
     Assert.Equal('t', characterSpan.Last.Value.GetChar());
 }
예제 #53
0
 public void IncludeLineBreakNextLineEmpty()
 {
     Create("cat", "", "dog");
     var span = _textBuffer.GetLine(0).ExtentIncludingLineBreak;
     var characterSpan = new CharacterSpan(span);
     Assert.Equal(1, characterSpan.LineCount);
     Assert.Equal(span, characterSpan.Span);
 }