private void SelectMarker(TextRangeCollection <Marker> markers, int selectIndex) { if (_currentFieldIndex >= 0 && _currentFieldIndex < markers.Count) { // Unselect marker. It changes style and no longer tracks editing. markers[_currentFieldIndex].StreamMarker.SetType(15); // 'Unselected legacy snippet field' markers[_currentFieldIndex].StreamMarker.SetBehavior( (uint)(MARKERBEHAVIORFLAGS2.MB_INHERIT_FOREGROUND | MARKERBEHAVIORFLAGS2.MB_DONT_DELETE_IF_ZEROLEN)); // 48 } if (selectIndex >= 0 && selectIndex < markers.Count) { _currentFieldIndex = selectIndex; var marker = markers[selectIndex]; // Flip stream marker into selected state. // It will change style and new behavior will cause it to expand with editing marker.StreamMarker.SetType(16); // 'Selected legacy snippet field' marker.StreamMarker.SetBehavior( (uint)(MARKERBEHAVIORFLAGS2.MB_INHERIT_FOREGROUND | MARKERBEHAVIORFLAGS2.MB_DONT_DELETE_IF_ZEROLEN) | (uint)(MARKERBEHAVIORFLAGS.MB_LEFTEDGE_LEFTTRACK | MARKERBEHAVIORFLAGS.MB_RIGHTEDGE_RIGHTTRACK)); // 54 var viewPoint = TextView.MapUpToView(new SnapshotPoint(GetTargetBuffer().CurrentSnapshot, marker.Start)); if (viewPoint.HasValue) { TextView.Selection.Select( new SnapshotSpan(TextView.TextBuffer.CurrentSnapshot, new Span(viewPoint.Value.Position, marker.Length)), isReversed: false); TextView.Caret.MoveTo(viewPoint.Value + marker.Length); } } }
public void TextRangeCollection_ItemsInRangeTest() { TextRangeCollection <TextRange> target = MakeCollection(); IReadOnlyList <TextRange> list = target.ItemsInRange(TextRange.EmptyRange); list.Should().BeEmpty(); list = target.ItemsInRange(TextRange.FromBounds(-10, -1)); list.Should().BeEmpty(); list = target.ItemsInRange(TextRange.FromBounds(0, Int32.MaxValue)); list.Should().HaveCount(3); list = target.ItemsInRange(TextRange.FromBounds(Int32.MinValue / 2, Int32.MaxValue / 2)); list.Should().HaveCount(3); list = target.ItemsInRange(TextRange.FromBounds(1, 7)); list.Should().HaveCount(3); list = target.ItemsInRange(TextRange.FromBounds(0, 8)); list.Should().HaveCount(3); list = target.ItemsInRange(TextRange.FromBounds(1, 1)); list.Should().BeEmpty(); // Zero-length ranges can't contain anything list = target.ItemsInRange(TextRange.FromBounds(1, 2)); list.Should().HaveCount(1); list = target.ItemsInRange(TextRange.FromBounds(1, 3)); list.Should().HaveCount(1); list = target.ItemsInRange(TextRange.FromBounds(1, 4)); list.Should().HaveCount(2); }
public void TextRangeCollection_GetFirstItemBeforePositionTest() { TextRangeCollection <TextRange> target = MakeCollection(); // 1-2, 3-5, 5-7 target.GetFirstItemBeforePosition(0).Should().Be(-1); target.GetFirstItemBeforePosition(-2).Should().Be(-1); target.GetFirstItemBeforePosition(1).Should().Be(-1); target.GetFirstItemBeforePosition(2).Should().Be(0); target.GetFirstItemBeforePosition(3).Should().Be(0); target.GetFirstItemBeforePosition(4).Should().Be(0); target.GetFirstItemBeforePosition(5).Should().Be(1); target.GetFirstItemBeforePosition(6).Should().Be(1); target.GetFirstItemBeforePosition(7).Should().Be(2); target.GetFirstItemBeforePosition(8).Should().Be(2); target.GetFirstItemBeforePosition(9).Should().Be(2); target.GetFirstItemBeforePosition(10).Should().Be(2); target.GetFirstItemBeforePosition(Int32.MaxValue).Should().Be(2); }
public void TextRangeCollection_RemoveInRangeTest5() { TextRangeCollection <TextRange> target = MakeCollection(); target.RemoveInRange(TextRange.FromBounds(0, 6)); target.Count.Should().Be(0); }
private void MakeLinesData() { if (_lineData != null) { return; } lock (_lock) { var data = new List <FullRangeLine>(); var lineStart = 0; for (var i = 0; i < _content.Length; i++) { var ch = _content[i]; if (ch.IsLineBreak()) { var lineBreakLength = 1; if (ch == '\r' && i + 1 < _content.Length && _content[i + 1] == '\n') { i++; lineBreakLength++; } else if (ch == '\n' && i + 1 < _content.Length && _content[i + 1] == '\r') { i++; lineBreakLength++; } data.Add(new FullRangeLine(new EditorLine(this, lineStart, i + 1 - lineStart - lineBreakLength, lineBreakLength, data.Count))); lineStart = i + 1; } } data.Add(new FullRangeLine(new EditorLine(this, lineStart, _content.Length - lineStart, 0, data.Count))); _lineData = new TextRangeCollection <FullRangeLine>(data); } }
public void RemoveChildren(int start, int count) { if (count == 0) return; if (start < 0 || start >= Children.Count) throw new ArgumentOutOfRangeException("start"); if (count < 0 || count > Children.Count || start + count > Children.Count) throw new ArgumentOutOfRangeException("count"); if (Children.Count == count) { _children = new TextRangeCollection<IAstNode>(); } else { var newChildren = new IAstNode[Children.Count - count]; int j = 0; for (int i = 0; i < start; i++, j++) newChildren[j] = Children[i]; for (int i = start; i < start + count; i++) Children[i].Parent = null; for (int i = start + count; i < Children.Count; i++, j++) newChildren[j] = Children[i]; _children = new TextRangeCollection<IAstNode>(newChildren); } }
public void TextRangeCollection_AddSorted() { ITextRange[] ranges = new ITextRange[3]; ranges[0] = TextRange.FromBounds(1, 2); ranges[1] = TextRange.FromBounds(3, 5); ranges[2] = TextRange.FromBounds(5, 7); TextRangeCollection <ITextRange> target = new TextRangeCollection <ITextRange>(); target.Count.Should().Be(0); target.Add(ranges[2]); target.Count.Should().Be(1); target.AddSorted(ranges[0]); target.Count.Should().Be(2); target.Start.Should().Be(1); target.End.Should().Be(7); target[0].Start.Should().Be(1); target[1].Start.Should().Be(5); target.AddSorted(ranges[1]); target.Count.Should().Be(3); target.Start.Should().Be(1); target.End.Should().Be(7); target[0].Start.Should().Be(1); target[1].Start.Should().Be(3); target[2].Start.Should().Be(5); target.Start.Should().Be(1); target.End.Should().Be(7); }
protected override IReadOnlyTextRangeCollection <RToken> GetTokens(int start, int length) { var tokenizer = new RTokenizer(); ITextProvider tp = new TextProvider(TextBuffer.CurrentSnapshot); var tokens = tokenizer.Tokenize(tp, 0, tp.Length); // In R there is [[ construct that comes as 'double square bracket' token. // Note that VS brace highlighter can only handle single-character braces. // Hence we'll massage token stream and replace double-bracket tokens but // a pair of square bracket tokens. var updated = new TextRangeCollection <RToken>(); foreach (var t in tokens) { switch (t.TokenType) { case RTokenType.OpenDoubleSquareBracket: updated.Add(new RToken(RTokenType.OpenSquareBracket, t.Start, 1)); updated.Add(new RToken(RTokenType.OpenSquareBracket, t.Start + 1, 1)); break; case RTokenType.CloseDoubleSquareBracket: updated.Add(new RToken(RTokenType.CloseSquareBracket, t.Start, 1)); updated.Add(new RToken(RTokenType.CloseSquareBracket, t.Start + 1, 1)); break; default: updated.Add(t); break; } } return(updated); }
public void TextRangeCollection_AddTest() { TextRange[] ranges = new TextRange[3]; ranges[0] = TextRange.FromBounds(1, 2); ranges[1] = TextRange.FromBounds(3, 5); ranges[2] = TextRange.FromBounds(5, 7); TextRangeCollection<TextRange> target = new TextRangeCollection<TextRange>(); target.Count.Should().Be(0); target.Add(ranges[0]); target.Count.Should().Be(1); target.Start.Should().Be(1); target.End.Should().Be(2); target.Length.Should().Be(1); target[0].Start.Should().Be(1); target.Add(ranges[1]); target.Count.Should().Be(2); target.Start.Should().Be(1); target.End.Should().Be(5); target.Length.Should().Be(4); target[0].Start.Should().Be(1); target[1].Start.Should().Be(3); target.Add(ranges[2]); target.Count.Should().Be(3); target.Start.Should().Be(1); target.End.Should().Be(7); target.Length.Should().Be(6); target[0].Start.Should().Be(1); target[1].Start.Should().Be(3); target[2].Start.Should().Be(5); }
public AstRoot(ITextProvider textProvider, ICodeEvaluator codeEvaluator) { TextProvider = textProvider; Comments = new CommentsCollection(); Errors = new TextRangeCollection <IParseError>(); CodeEvaluator = codeEvaluator; }
public void TextRangeCollection_ConstructorTest() { TextRangeCollection<TextRange> target = new TextRangeCollection<TextRange>(); target.Count.Should().Be(0); target.Start.Should().Be(0); target.End.Should().Be(0); target.Length.Should().Be(0); }
private static void AssertEquals(TextRangeCollection<TextRange> target, params int[] values) { target.Count.Should().Be(values.Length/2); for (int i = 0; i < values.Length; i += 2) { target[i / 2].Start.Should().Be(values[i]); target[i / 2].End.Should().Be(values[i + 1]); } }
public void AddOrphanedEndTag(TagNode tag) { if (OrphanedEndTagsCollection == null) { OrphanedEndTagsCollection = new TextRangeCollection <TagNode>(); } OrphanedEndTagsCollection.Add(tag); }
protected override void RemoveSensitiveTokens(int position, TextRangeCollection <RdToken> tokens) { if (Tokens.Count > 0) { Tokens.RemoveInRange(new TextRange(position, Tokens[Tokens.Count - 1].End)); } base.RemoveSensitiveTokens(position, tokens); }
internal virtual void InitializeTokenizer(ITextProvider textProvider, int start, int length) { Debug.Assert(start >= 0 && length >= 0 && start + length <= textProvider.Length); _cs = new CharacterStream(textProvider); _cs.Position = start; _tokens = new TextRangeCollection <T>(); }
public void TextRangeCollection_ConstructorTest() { TextRangeCollection <TextRange> target = new TextRangeCollection <TextRange>(); target.Count.Should().Be(0); target.Start.Should().Be(0); target.End.Should().Be(0); target.Length.Should().Be(0); }
private static void AssertEquals(TextRangeCollection <TextRange> target, params int[] values) { target.Count.Should().Be(values.Length / 2); for (int i = 0; i < values.Length; i += 2) { target[i / 2].Start.Should().Be(values[i]); target[i / 2].End.Should().Be(values[i + 1]); } }
public void TextRangeCollection_RemoveInRangeTest2() { TextRangeCollection <TextRange> target = MakeCollection(); target.RemoveInRange(TextRange.FromBounds(Int32.MinValue / 2, Int32.MaxValue / 2)); target.Count.Should().Be(0); target.Start.Should().Be(0); target.End.Should().Be(0); }
public void TextRangeCollection_RemoveInRangeTest6() { TextRangeCollection <TextRange> target = MakeCollection(); target.RemoveInRange(TextRange.FromBounds(0, 5)); AssertEquals(target, 5, 7); target.Start.Should().Be(5); target.End.Should().Be(7); }
public void TextRangeCollection_ReflectTextChangeTest4() { TextRangeCollection <TextRange> target = MakeCollection(); AssertEquals(target, 1, 2, 3, 5, 5, 7); target.ReflectTextChange(3, 0, 3); AssertEquals(target, 1, 2, 6, 8, 8, 10); target.Start.Should().Be(1); target.End.Should().Be(10); }
public void TextRangeCollection_ShiftTest() { TextRangeCollection <TextRange> target = MakeCollection(); AssertEquals(target, 1, 2, 3, 5, 5, 7); target.Shift(2); AssertEquals(target, 3, 4, 5, 7, 7, 9); target.Shift(-3); AssertEquals(target, 0, 1, 2, 4, 4, 6); }
public void TextRangeCollection_ReflectTextChangeTest1() { TextRangeCollection <TextRange> target = MakeCollection(); target.ReflectTextChange(0, 0, 1); AssertEquals(target, 2, 3, 4, 6, 6, 8); target.ReflectTextChange(0, 1, 0); AssertEquals(target, 1, 2, 3, 5, 5, 7); target.Start.Should().Be(1); target.End.Should().Be(7); }
public TokenBasedClassifier(ITextBuffer textBuffer, ITokenizer <TTokenClass> tokenizer, IClassificationNameProvider <TTokenClass> classificationNameProvider) { _classificationNameProvider = classificationNameProvider; Tokenizer = tokenizer; TextBuffer = textBuffer; TextBuffer.Changed += OnTextChanged; Tokens = new TextRangeCollection <TTokenClass>(); }
/// <summary> /// Determines if a given range is inside a comment and /// returns range of the comment block. /// </summary> /// <param name="range">Text range to check</param> /// <returns>Text range of the found comment block or empty range if not found.</returns> public ITextRange GetCommentBlockContainingRange(ITextRange range) { TextRangeCollection <RToken> comments = this.AstRoot.Comments; var commentsInRange = comments.ItemsInRange(range); if (commentsInRange.Count == 1) { return(commentsInRange[0]); } return(TextRange.EmptyRange); }
public void TextRangeCollection_ConstructorTest1() { TextRangeCollection <TextRange> target = MakeCollection(); target.Count.Should().Be(3); target.Start.Should().Be(1); target.End.Should().Be(7); target.Length.Should().Be(6); target[0].Start.Should().Be(1); target[1].Start.Should().Be(3); target[2].Start.Should().Be(5); }
public void TextRangeCollection_ReflectTextChangeTest3() { TextRangeCollection <TextRange> target = MakeCollection(); target.ReflectTextChange(3, 1, 4); AssertEquals(target, 1, 2, 3, 8, 8, 10); target.ReflectTextChange(0, 15, 20); AssertEquals(target); target.Count.Should().Be(0); target.Start.Should().Be(0); target.End.Should().Be(0); }
public void TextRangeCollection_GetItemsContainingInclusiveEndTest() { TextRangeCollection <TextRange> target = MakeCollection(); IReadOnlyList <int> list = target.GetItemsContainingInclusiveEnd(0); list.Should().BeEmpty(); list = target.GetItemsContainingInclusiveEnd(-2); list.Should().BeEmpty(); list = target.GetItemsContainingInclusiveEnd(1); list.Should().HaveCount(1); list[0].Should().Be(0); list = target.GetItemsContainingInclusiveEnd(2); list.Should().HaveCount(1); list[0].Should().Be(0); list = target.GetItemsContainingInclusiveEnd(3); list.Should().HaveCount(1); list[0].Should().Be(1); list = target.GetItemsContainingInclusiveEnd(4); list.Should().HaveCount(1); list[0].Should().Be(1); list = target.GetItemsContainingInclusiveEnd(5); list.Should().HaveCount(2); list[0].Should().Be(1); list[1].Should().Be(2); list = target.GetItemsContainingInclusiveEnd(6); list.Should().HaveCount(1); list[0].Should().Be(2); list = target.GetItemsContainingInclusiveEnd(7); list.Should().HaveCount(1); list[0].Should().Be(2); list = target.GetItemsContainingInclusiveEnd(8); list.Should().BeEmpty(); list = target.GetItemsContainingInclusiveEnd(10); list.Should().BeEmpty(); list = target.GetItemsContainingInclusiveEnd(Int32.MaxValue); list.Should().BeEmpty(); }
public void TextRangeCollection_RemoveAtTest() { TextRangeCollection <TextRange> target = MakeCollection(); AssertEquals(target, 1, 2, 3, 5, 5, 7); target.RemoveAt(0); AssertEquals(target, 3, 5, 5, 7); target.RemoveAt(1); AssertEquals(target, 3, 5); target.RemoveAt(0); AssertEquals(target); }
protected override void RemoveSensitiveTokens(int position, TextRangeCollection <MarkdownToken> tokens) { // Check if change damages code block. Normally base classifier removes all tokens // from the caret position to the end of the visible area. If typing is inside // the code area it may also affects tokens starting from the beginning of the code // block. For example, when user types ``` in a middle of existing ```...``` block. // This is similar to typing %> or ?> in a middle of ASP.NET or PHP block. int last = tokens.Count - 1; if (last >= 0 && tokens[last].TokenType == MarkdownTokenType.Code) { tokens.RemoveAt(last); } base.RemoveSensitiveTokens(position, tokens); }
public void TextRangeCollection_RemoveInRangeTest8() { TextRangeCollection <TextRange> target = MakeCollection(); target.RemoveInRange(TextRange.FromBounds(0, 0), inclusiveEnds: true); target.Count.Should().Be(3); target.RemoveInRange(TextRange.FromBounds(0, 1), inclusiveEnds: true); target.Count.Should().Be(2); target.RemoveInRange(TextRange.FromBounds(5, 5), inclusiveEnds: true); target.Count.Should().Be(1); target.Start.Should().Be(3); target.End.Should().Be(5); }
public void TextRangeCollection_ContainsTest() { TextRangeCollection <TextRange> target = MakeCollection(); target.Contains(1).Should().BeTrue(); target.Contains(2).Should().BeTrue(); target.Contains(3).Should().BeTrue(); target.Contains(4).Should().BeTrue(); target.Contains(5).Should().BeTrue(); target.Contains(6).Should().BeTrue(); target.Contains(-10).Should().BeFalse(); target.Contains(0).Should().BeFalse(); target.Contains(7).Should().BeFalse(); target.Contains(Int32.MaxValue).Should().BeFalse(); }
public void TextRangeCollection_ShiftStartingFromTest() { TextRangeCollection <TextRange> target = MakeCollection(); target.ShiftStartingFrom(3, 4); AssertEquals(target, 1, 2, 3, 9, 9, 11); target.ShiftStartingFrom(1, -1); AssertEquals(target, 0, 1, 2, 8, 8, 10); target.ShiftStartingFrom(22, 10); AssertEquals(target, 0, 1, 2, 8, 8, 10); target.Start.Should().Be(0); target.End.Should().Be(10); }
public void TextRangeCollection_GetItemAtPositionTest() { TextRangeCollection <TextRange> target = MakeCollection(); target.GetItemAtPosition(0).Should().Be(-1); target.GetItemAtPosition(-2).Should().Be(-1); target.GetItemAtPosition(1).Should().Be(0); target.GetItemAtPosition(2).Should().Be(-1); target.GetItemAtPosition(3).Should().Be(1); target.GetItemAtPosition(4).Should().Be(-1); target.GetItemAtPosition(5).Should().Be(2); target.GetItemAtPosition(10).Should().Be(-1); target.GetItemAtPosition(Int32.MaxValue).Should().Be(-1); }
public void RemoveChildren(int start, int count) { if (count == 0) { return; } if (start < 0 || start >= Children.Count) { throw new ArgumentOutOfRangeException("start"); } if (count < 0 || count > Children.Count || start + count > Children.Count) { throw new ArgumentOutOfRangeException("count"); } if (Children.Count == count) { _children = new TextRangeCollection <IAstNode>(); } else { var newChildren = new IAstNode[Children.Count - count]; int j = 0; for (int i = 0; i < start; i++, j++) { newChildren[j] = Children[i]; } for (int i = start; i < start + count; i++) { Children[i].Parent = null; } for (int i = start + count; i < Children.Count; i++, j++) { newChildren[j] = Children[i]; } _children = new TextRangeCollection <IAstNode>(newChildren); } }
public AstRoot(ITextProvider textProvider, ICodeEvaluator codeEvaluator) { TextProvider = textProvider; Comments = new CommentsCollection(); Errors = new TextRangeCollection<IParseError>(); CodeEvaluator = codeEvaluator; }
private void SelectMarker(TextRangeCollection<Marker> markers, int selectIndex) { if (_currentFieldIndex >= 0 && _currentFieldIndex < markers.Count) { // Unselect marker. It changes style and no longer tracks editing. markers[_currentFieldIndex].StreamMarker.SetType(15); // 'Unselected legacy snippet field' markers[_currentFieldIndex].StreamMarker.SetBehavior( (uint)(MARKERBEHAVIORFLAGS2.MB_INHERIT_FOREGROUND | MARKERBEHAVIORFLAGS2.MB_DONT_DELETE_IF_ZEROLEN)); // 48 } if (selectIndex >= 0 && selectIndex < markers.Count) { _currentFieldIndex = selectIndex; var marker = markers[selectIndex]; // Flip stream marker into selected state. // It will change style and new behavior will cause it to expand with editing marker.StreamMarker.SetType(16); // 'Selected legacy snippet field' marker.StreamMarker.SetBehavior( (uint)(MARKERBEHAVIORFLAGS2.MB_INHERIT_FOREGROUND | MARKERBEHAVIORFLAGS2.MB_DONT_DELETE_IF_ZEROLEN) | (uint)(MARKERBEHAVIORFLAGS.MB_LEFTEDGE_LEFTTRACK | MARKERBEHAVIORFLAGS.MB_RIGHTEDGE_RIGHTTRACK)); // 54 var viewPoint = TextView.MapUpToView(new SnapshotPoint(GetTargetBuffer().CurrentSnapshot, marker.Start)); if (viewPoint.HasValue) { TextView.Selection.Select( new SnapshotSpan(TextView.TextBuffer.CurrentSnapshot, new Span(viewPoint.Value.Position, marker.Length)), isReversed: false); TextView.Caret.MoveTo(viewPoint.Value + marker.Length); } } }
public CodeBlockInfo() { CodeLines = new TextRangeCollection<CodeLineArtifact>(); }
public void AddOrphanedEndTag(TagNode tag) { if (OrphanedEndTagsCollection == null) OrphanedEndTagsCollection = new TextRangeCollection<TagNode>(); OrphanedEndTagsCollection.Add(tag); }