public static Position ToPosition(SnapshotPoint corePoint, ITextSnapshot snapshot = null) { SnapshotPoint snapshotPoint = corePoint.TranslateTo(snapshot ?? corePoint.Snapshot, PointTrackingMode.Positive); ITextSnapshotLine containingLine = snapshotPoint.GetContainingLine(); int charIndex = Math.Max(snapshotPoint.Position - containingLine.Start.Position, 0); return new Position(containingLine.LineNumber, charIndex); }
private void FormatOnEnter(SnapshotPoint start, SnapshotPoint end) { if (NodejsPackage.Instance.FormattingGeneralOptionsPage.FormatOnEnter) { var insertionPoint = _textView.BufferGraph.MapDownToInsertionPoint( _textView.Caret.Position.BufferPosition, PointTrackingMode.Negative, x => x.ContentType.IsOfType(NodejsConstants.Nodejs) ); if (insertionPoint != null) { var buffer = insertionPoint.Value.Snapshot.TextBuffer; var line = insertionPoint.Value.GetContainingLine(); if (line.LineNumber > 0) { SnapshotSpan commentSpan; if (insertionPoint.Value.IsMultilineComment(out commentSpan)) { _textView.FormatMultilineComment(commentSpan.Start, insertionPoint.Value); } else { ApplyEdits( buffer, Formatter.GetEditsAfterEnter( buffer.CurrentSnapshot.GetText(), start.TranslateTo(buffer.CurrentSnapshot, PointTrackingMode.Negative), end.TranslateTo(buffer.CurrentSnapshot, PointTrackingMode.Positive), CreateFormattingOptions() ) ); } } } } }
private SnapshotPoint?CheckedMapUpToBuffer(SnapshotPoint point, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match, PositionAffinity affinity) { if (point.Snapshot == null) { throw new ArgumentNullException("point"); } if (trackingMode < PointTrackingMode.Positive || trackingMode > PointTrackingMode.Negative) { throw new ArgumentOutOfRangeException("trackingMode"); } if (affinity < PositionAffinity.Predecessor || affinity > PositionAffinity.Successor) { throw new ArgumentOutOfRangeException("affinity"); } if (!this.importingProjectionBufferMap.ContainsKey(point.Snapshot.TextBuffer)) { return(null); } else { SnapshotPoint currentPoint = point.TranslateTo(point.Snapshot.TextBuffer.CurrentSnapshot, trackingMode); return(MapUpToBufferGuts(currentPoint, affinity, match)); } }
/// <summary> /// Override for the FrameworkElement's OnRender. When called, redraw /// all of the markers /// </summary> protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (_search != null) { //There is a word that should be highlighted. It doesn't matter whether or not the search has completed or //is still in progress: draw red marks for each match found so far (the completion callback on the search //will guarantee that the highlight display gets invalidated once the search has completed). //Take a snapshot of the matches found to date (this could still be changing //if the search has not completed yet). IList <SnapshotSpan> matches = _search.Matches; double lastY = double.MinValue; int markerCount = Math.Min(500, matches.Count); for (int i = 0; (i < markerCount); ++i) { //Get (for small lists) the index of every match or, for long lists, the index of every //(count / 1000)th entry. Use longs to avoid any possible integer overflow problems. int index = (int)(((long)(i) * (long)(matches.Count)) / ((long)markerCount)); SnapshotPoint match = matches[index].Start; //Translate the match from its snapshot to the view's current snapshot (the versions should be the same, //but this will handle it if -- for some reason -- they are not). double y = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(match.TranslateTo(_textView.TextSnapshot, PointTrackingMode.Negative))); if (y + MarkThickness > lastY) { lastY = y; this.DrawMark(drawingContext, _marginMatchBrush, y); } } } }
public SnapshotPoint?MapDownToInsertionPoint(SnapshotPoint position, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match) { var snapshot = position.Snapshot; var buffer = snapshot.TextBuffer; int pos = position.TranslateTo(snapshot, trackingMode); while (!match(snapshot)) { var projBuffer = buffer as IProjectionBufferBase; if (projBuffer == null) { return(null); } var projSnapshot = projBuffer.CurrentSnapshot; if (projSnapshot.SourceSnapshots.Count == 0) { return(null); } var pt = projSnapshot.MapToSourceSnapshot(pos); pos = pt.Position; snapshot = pt.Snapshot; buffer = snapshot.TextBuffer; } return(new SnapshotPoint(snapshot, pos)); }
public void MoveCaret(SnapshotPoint newPoint) { Invoke((Action)(() => { TextView.Caret.MoveTo(newPoint.TranslateTo(newPoint.Snapshot.TextBuffer.CurrentSnapshot, PointTrackingMode.Positive)); })); }
public static Position ToPosition(SnapshotPoint corePoint, ITextSnapshot snapshot = null) { SnapshotPoint snapshotPoint = corePoint.TranslateTo(snapshot ?? corePoint.Snapshot, PointTrackingMode.Positive); ITextSnapshotLine containingLine = snapshotPoint.GetContainingLine(); int charIndex = Math.Max(snapshotPoint.Position - containingLine.Start.Position, 0); return(new Position(containingLine.LineNumber, charIndex)); }
public SnapshotPoint?GetPoint(ITextSnapshot targetSnapshot, PositionAffinity affinity) { if (targetSnapshot == null) { throw new ArgumentNullException(nameof(targetSnapshot)); } return(snapshotPoint.TranslateTo(targetSnapshot, trackingMode)); }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) //there is no content in the buffer { yield break; } //don't do anything if the current SnapshotPoint is not initialized or at the end of the buffer if (!CurrentChar.HasValue || CurrentChar.Value.Position >= CurrentChar.Value.Snapshot.Length) { yield break; } //hold on to a snapshot of the current character SnapshotPoint currentChar = CurrentChar.Value; //if the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } //if we are outside the snapshot, bail if (currentChar.Position >= currentChar.Snapshot.Length) { yield break; } //get the current char and the previous char char currentText = currentChar.GetChar(); SnapshotPoint lastChar = currentChar == 0 ? currentChar : currentChar - 1; //if currentChar is 0 (beginning of buffer), don't move it back char lastText = lastChar.GetChar(); SnapshotSpan pairSpan = new SnapshotSpan(); if (braceList.ContainsKey(currentText)) //the key is the open brace { char closeChar; braceList.TryGetValue(currentText, out closeChar); if (VisualRustBraceMatcher.FindMatchingCloseChar(currentChar, currentText, closeChar, View.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), new TextMarkerTag("bracehighlight"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("bracehighlight"))); } } else if (braceList.ContainsValue(lastText)) //the value is the close brace, which is the *previous* character { var open = from n in braceList where n.Value.Equals(lastText) select n.Key; if (VisualRustBraceMatcher.FindMatchingOpenChar(lastChar, (char)open.ElementAt <char>(0), lastText, View.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(lastChar, 1), new TextMarkerTag("bracehighlight"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("bracehighlight"))); } } }
public SnapshotPoint GetNearestPointInVisualSnapshot(SnapshotPoint editBufferPoint, ITextSnapshot targetVisualSnapshot, PointTrackingMode trackingMode) { // editBufferPoint MUST be in the editBuffer according to the docs if (editBufferPoint.Snapshot.TextBuffer != this.EditBuffer) { throw new InvalidOperationException("editBufferPoint is not on the edit buffer"); } return(editBufferPoint.TranslateTo(targetVisualSnapshot, PointTrackingMode.Positive)); }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) //there is no content in the buffer { yield break; } //don't do anything if the current SnapshotPoint is not initialized if (!CurrentChar.HasValue) { yield break; } //hold on to a snapshot of the current character SnapshotPoint currentChar = CurrentChar.Value; //if the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } if (currentChar.Position < spans[0].Snapshot.Length) { // Check if the current character is an open brace char ch = currentChar.GetChar(); char closeCh; if (MatchBrace(currentChar, ch, true, out closeCh)) { SnapshotSpan pairSpan; if (FindMatchingCloseChar(currentChar, ch, closeCh, View.TextViewLines.Count, out pairSpan)) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), Blue)); yield return(new TagSpan <TextMarkerTag>(pairSpan, Blue)); } } } if (0 < currentChar.Position) { // Check if the previous character is a close brace (note, caret may be between a close brace and an open brace, in which case we'll tag two pairs) SnapshotPoint prevChar = currentChar - 1; char ch = prevChar.GetChar(); char openCh; if (MatchBrace(prevChar, ch, false, out openCh)) { SnapshotSpan pairSpan; if (FindMatchingOpenChar(prevChar, openCh, ch, View.TextViewLines.Count, out pairSpan)) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(prevChar, 1), Blue)); yield return(new TagSpan <TextMarkerTag>(pairSpan, Blue)); } } } }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) { yield break; } // don't do anything if the current SnapshotPoint is not initialized or at the end of the buffer if (!CurrentChar.HasValue || CurrentChar.Value.Position >= CurrentChar.Value.Snapshot.Length) { yield break; } // hold on to a snapshot of the current character SnapshotPoint currentChar = CurrentChar.Value; if (IsInCommentOrLiteral(Classifier, currentChar, TextView.Caret.Position.Affinity)) { yield break; } // if the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); // get the current char and the previous char char currentText = currentChar.GetChar(); // if current char is 0 (beginning of buffer), don't move it back SnapshotPoint lastChar = currentChar == 0 ? currentChar : currentChar - 1; char lastText = lastChar.GetChar(); SnapshotSpan pairSpan = new SnapshotSpan(); if (IsMatchStartCharacter(currentText)) { char closeChar = GetMatchCloseCharacter(currentText); /* TODO: Need to improve handling of larger blocks. this won't highlight if the matching brace is more * than 1 screen's worth of lines away. Changing this to 10 * TextView.TextViewLines.Count seemed * to improve the situation. */ if (BraceMatchingTagger.FindMatchingCloseChar(currentChar, Classifier, currentText, closeChar, 10 * TextView.TextViewLines.Count, out pairSpan)) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), BraceHighlightTag)); yield return(new TagSpan <TextMarkerTag>(pairSpan, BraceHighlightTag)); } } else if (IsMatchCloseCharacter(lastText)) { var open = GetMatchOpenCharacter(lastText); if (BraceMatchingTagger.FindMatchingOpenChar(lastChar, Classifier, open, lastText, 10 * TextView.TextViewLines.Count, out pairSpan)) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(lastChar, 1), BraceHighlightTag)); yield return(new TagSpan <TextMarkerTag>(pairSpan, BraceHighlightTag)); } } }
private ITextViewLine GetLineByPos(CaretPosition pos) { SnapshotPoint point = pos.BufferPosition; if (point.Snapshot != this.view.TextSnapshot) { point = point.TranslateTo(this.view.TextSnapshot, PointTrackingMode.Positive); } return(this.view.GetTextViewLineContainingBufferPosition(point)); }
public SnapshotPoint?MapDownToFirstMatch(SnapshotPoint position, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match, PositionAffinity affinity) { var buffer = _buffers.FirstOrDefault(b => match(b.CurrentSnapshot)); if (buffer != null) { return(position.TranslateTo(buffer.CurrentSnapshot, trackingMode)); } return(null); }
public SnapshotPoint? MapDownToBuffer(SnapshotPoint position, PointTrackingMode trackingMode, ITextBuffer targetBuffer, PositionAffinity affinity) { if (position.Snapshot == null) throw new ArgumentException(); if (targetBuffer == null) throw new ArgumentNullException(nameof(targetBuffer)); if (position.Snapshot.TextBuffer != TopBuffer) return null; if (TopBuffer != targetBuffer) return null; return position.TranslateTo(targetBuffer.CurrentSnapshot, trackingMode); }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) //there is no content in the buffer { yield break; } //don't do anything if the current SnapshotPoint is not initialized or at the end of the buffer if (!CurrentChar.HasValue || CurrentChar.Value.Position >= CurrentChar.Value.Snapshot.Length) { yield break; } //hold on to a snapshot of the current character SnapshotPoint currentChar = CurrentChar.Value; //if the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } if (currentChar.Position > 0) { currentChar -= 1; } var bracelist = SourceBuffer.Properties[SnapshotSpanPair.BraceKey] as List <SnapshotSpanPair>; foreach (var pair in bracelist) { if (pair.Start.IsEmpty || pair.End.IsEmpty) { continue; } if (pair.Start.Snapshot != currentChar.Snapshot) { pair.Start = pair.Start.TranslateTo(currentChar.Snapshot, SpanTrackingMode.EdgeExclusive); } if (pair.End.Snapshot != currentChar.Snapshot) { pair.End = pair.End.TranslateTo(currentChar.Snapshot, SpanTrackingMode.EdgeExclusive); } if (pair.Start.Contains(currentChar) || pair.End.Contains(currentChar)) { yield return(new TagSpan <TextMarkerTag>(pair.Start, new TextMarkerTag("blue"))); yield return(new TagSpan <TextMarkerTag>(pair.End, new TextMarkerTag("blue"))); break; } } }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { // Don't do anything if there is no content in the buffer or // the current SnapshotPoint is not initialized or at the end of the buffer . if (spans.Count == 0 || !_currentChar.HasValue || _currentChar.Value.Position > _currentChar.Value.Snapshot.Length) { yield break; } // If the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot. SnapshotPoint currentChar = _currentChar.Value; if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } // Get the current char and the previous char. SnapshotPoint lastChar = currentChar == 0 ? currentChar : currentChar - 1; SnapshotSpan pairSpan = new SnapshotSpan(); char currentText; char lastText; char closeChar; if (currentChar.Position < currentChar.Snapshot.Length - 1 && _braceList.TryGetValue(currentText = currentChar.GetChar(), out closeChar)) { // The value is an opening brace, which is the *next/current* character, we will find the closing character. if (BraceMatchingTagger.FindMatchingCloseChar(currentChar, currentText, closeChar, _view.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), _tag)); yield return(new TagSpan <TextMarkerTag>(pairSpan, _tag)); } } else if (currentChar.Snapshot.Length > 1 && lastChar.Position < currentChar.Snapshot.Length && _braceList.ContainsValue(lastText = lastChar.GetChar())) { // The value is a closing brace, which is the *previous* character, we will find the opening character. var open = from n in _braceList where n.Value.Equals(lastText) select n.Key; if (BraceMatchingTagger.FindMatchingOpenChar(lastChar, open.Single(), lastText, _view.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(lastChar, 1), _tag)); yield return(new TagSpan <TextMarkerTag>(pairSpan, _tag)); } } }
public override void Invoke(CancellationToken cancellationToken) { // Get the range for the current snapshot ITextSnapshot snapshot = _textView.TextSnapshot; SnapshotPoint target = _target.TranslateTo(snapshot, PointTrackingMode.Positive); int startLineIndex = snapshot.GetLineNumberFromPosition(target); int endLineIndex = startLineIndex; // Find first #include of block while (startLineIndex > 0 && LineIsInclude(snapshot, startLineIndex - 1)) { startLineIndex--; } // Find last #include of block while (endLineIndex < snapshot.LineCount - 1 && LineIsInclude(snapshot, endLineIndex + 1)) { endLineIndex++; } // Get includes int numIncludeLines = endLineIndex - startLineIndex + 1; var lines = new Tuple <string, string> [numIncludeLines]; for (int i = startLineIndex; i <= endLineIndex; i++) { ITextSnapshotLine line = snapshot.GetLineFromLineNumber(i); string lineText = line.GetText(); string includePath = GetIncludePath(snapshot, lineText); lines[i - startLineIndex] = new Tuple <string, string>(lineText, includePath); } // Sort (use LINQ as its stable) lines = lines.OrderBy(x => x.Item2.StartsWith("<") ? 0 : 1) .ThenBy(x => x.Item2) .ToArray(); // Replace the lines with the new sorted lines ITextSnapshotLine startLine = snapshot.GetLineFromLineNumber(startLineIndex); ITextSnapshotLine endLine = snapshot.GetLineFromLineNumber(endLineIndex); string newLineChar = _textView.Options.GetNewLineCharacter(); using (ITextEdit edit = _textBuffer.CreateEdit(EditOptions.DefaultMinimalChange, null, null)) { var replaceSpan = Span.FromBounds(startLine.Start, endLine.End); string replaceText = String.Join(newLineChar, lines.Select(x => x.Item1)); edit.Replace(replaceSpan, replaceText); edit.Apply(); } }
SnapshotSpan? FindNextResultCore(FindOptions options, SnapshotPoint startingPosition) { if (SearchString.Length == 0) return null; var snapshot = wpfTextView.TextSnapshot; startingPosition = startingPosition.TranslateTo(snapshot, PointTrackingMode.Negative); var searchRange = new SnapshotSpan(snapshot, 0, snapshot.Length); try { return textSearchService2.Find(searchRange, startingPosition, SearchString, options); } catch (ArgumentException) when ((options & FindOptions.UseRegularExpressions) != 0) { // Invalid regex string return null; } }
public IEnumerable <ErrorTask> GetErrorMessagesAtPoint(string fileName, SnapshotPoint pt) { foreach (var task in (from t in Tasks.Cast <ErrorTask>() where string.Equals(t.Document, fileName, StringComparison.OrdinalIgnoreCase) select t)) { var span = task.Span; if (span.HasValue) { if (span.Value.Contains(pt.TranslateTo(task.GetSnapshot(pt.Snapshot), PointTrackingMode.Positive))) { yield return(task); } } else { var taskLine = task.GetSnapshot(pt.Snapshot).GetLineFromLineNumber(task.Line); var taskSpan = new SnapshotSpan(taskLine.Start, taskLine.End); if (taskSpan.Contains(pt.TranslateTo(taskSpan.Snapshot, PointTrackingMode.Positive))) { yield return(task); } } } }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) { //there is no content in the buffer yield break; } //don't do anything if the current SnapshotPoint is not initialized or at the end of the buffer if (!this.currentChar_.HasValue || this.currentChar_.Value.Position >= this.currentChar_.Value.Snapshot.Length) { yield break; } //hold on to a snapshot of the current character SnapshotPoint currentChar = this.currentChar_.Value; //if the requested snapshot isn't the same as the one the brace is on, translate our spans to the expected snapshot if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } //get the current char and the previous char char currentText = currentChar.GetChar(); SnapshotPoint lastChar = currentChar == 0 ? currentChar : currentChar - 1; //if currentChar is 0 (beginning of buffer), don't move it back char lastText = lastChar.GetChar(); SnapshotSpan pairSpan = default(SnapshotSpan); if (this.braceList_.ContainsKey(currentText)) { //the key is the open brace this.braceList_.TryGetValue(currentText, out char closeChar); if (FindMatchingCloseChar(currentChar, currentText, closeChar, this.view_.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), new TextMarkerTag("blue"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("blue"))); } } else if (this.braceList_.ContainsValue(lastText)) { //the value is the close brace, which is the *previous* character IEnumerable <char> open = from n in this.braceList_ where n.Value.Equals(lastText) select n.Key; if (FindMatchingOpenChar(lastChar, open.ElementAt(0), lastText, this.view_.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(lastChar, 1), new TextMarkerTag("blue"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("blue"))); } } }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0) { yield break; } if (!CurrentChar.HasValue || CurrentChar.Value.Position >= CurrentChar.Value.Snapshot.Length) { yield break; } SnapshotPoint currentChar = CurrentChar.Value; if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } char currentText = currentChar.GetChar(); SnapshotPoint lastChar = currentChar == 0 ? currentChar : currentChar - 1; char lastText = lastChar.GetChar(); SnapshotSpan pairSpan = new SnapshotSpan(); if (_braceList.ContainsKey(currentText)) { char closeChar; _braceList.TryGetValue(currentText, out closeChar); if (FindMatchingCloseChar(currentChar, currentText, closeChar, View.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(currentChar, 1), new TextMarkerTag("blue"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("blue"))); } } else if (_braceList.ContainsValue(lastText)) { var open = from n in _braceList where n.Value.Equals(lastText) select n.Key; if (FindMatchingOpenChar(lastChar, (char)open.ElementAt <char>(0), lastText, View.TextViewLines.Count, out pairSpan) == true) { yield return(new TagSpan <TextMarkerTag>(new SnapshotSpan(lastChar, 1), new TextMarkerTag("blue"))); yield return(new TagSpan <TextMarkerTag>(pairSpan, new TextMarkerTag("blue"))); } } }
protected virtual bool IsSnapshotPointContainedInSpan(ITextSnapshot snapshot, SnapshotPoint snapshotPoint, SnapshotSpan sourceSpan) { if (snapshot != sourceSpan.Snapshot) { // need to map to the new snapshot before we can detect overlap sourceSpan = sourceSpan.TranslateTo(snapshot, SpanTrackingMode.EdgeExclusive); } if (snapshot != snapshotPoint.Snapshot) { // need to map to the new snapshot before we can detect overlap snapshotPoint = snapshotPoint.TranslateTo(snapshot, PointTrackingMode.Positive); } return(sourceSpan.Contains(snapshotPoint)); }
void VisualElement_SizeChanged(object sender, SizeChangedEventArgs e) { if (e.NewSize.Height == 0) { return; } codeDocument.TextView.VisualElement.SizeChanged -= VisualElement_SizeChanged; Debug.Assert(initialPosition.Snapshot != null); if (initialPosition.Snapshot == null) { return; } codeDocument.TextView.Caret.MoveTo(initialPosition.TranslateTo(codeDocument.TextView.TextSnapshot, PointTrackingMode.Negative)); codeDocument.TextView.EnsureCaretVisible(true); }
public SnapshotPoint?MapDownToFirstMatch(SnapshotPoint position, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match, PositionAffinity affinity) { if (position.Snapshot == null) { throw new ArgumentNullException("position"); } if (trackingMode < PointTrackingMode.Positive || trackingMode > PointTrackingMode.Negative) { throw new ArgumentOutOfRangeException("trackingMode"); } if (match == null) { throw new ArgumentNullException("match"); } if (affinity < PositionAffinity.Predecessor || affinity > PositionAffinity.Successor) { throw new ArgumentOutOfRangeException("affinity"); } if (!this.importingProjectionBufferMap.ContainsKey(position.Snapshot.TextBuffer)) { return(null); } ITextBuffer currentBuffer = position.Snapshot.TextBuffer; ITextSnapshot currentSnapshot = currentBuffer.CurrentSnapshot; int currentPosition = position.TranslateTo(currentSnapshot, trackingMode).Position; while (!match(currentSnapshot)) { IProjectionBufferBase projBuffer = currentBuffer as IProjectionBufferBase; if (projBuffer == null) { return(null); } IProjectionSnapshot projSnap = projBuffer.CurrentSnapshot; if (projSnap.SourceSnapshots.Count == 0) { return(null); } SnapshotPoint currentPoint = projSnap.MapToSourceSnapshot(currentPosition, affinity); currentPosition = currentPoint.Position; currentSnapshot = currentPoint.Snapshot; currentBuffer = currentSnapshot.TextBuffer; } return(new SnapshotPoint(currentSnapshot, currentPosition)); }
public IEnumerable <ITagSpan <TextMarkerTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (spans.Count == 0 || Buffer.CurrentSnapshot.Length == 0) { yield break; } if (!CurrentChar.HasValue || CurrentChar.Value.Position >= CurrentChar.Value.Snapshot.Length) { yield break; } SnapshotPoint currentChar = CurrentChar.Value; if (spans[0].Snapshot != currentChar.Snapshot) { currentChar = currentChar.TranslateTo(spans[0].Snapshot, PointTrackingMode.Positive); } var allTags = _vendorClassifier.GetClassificationSpans(spans[0]).Where(s => s.ClassificationType.Classification == ClassificationTypes._value); foreach (var tagSpan in allTags) { if (tagSpan.Span.Contains(currentChar)) { Declaration dec = _vendorClassifier.Cache.FirstOrDefault(e => currentChar.Position > e.Start && currentChar.Position < e.AfterEnd); if (dec != null && dec.PropertyName.Text.Length > 0 && !dec.IsVendorSpecific()) { foreach (Declaration vendor in _vendorClassifier.Cache.Where(d => d.Parent == dec.Parent && _vendorClassifier.GetStandardName(d) == dec.PropertyName.Text)) { // Manage quotes for -ms-filter string value = Buffer.CurrentSnapshot.GetText(vendor.Colon.AfterEnd, vendor.AfterEnd - vendor.Colon.AfterEnd); int quotes = value.StartsWith("'") || value.StartsWith("\"") ? 1 : 0; SnapshotSpan vendorSpan = new SnapshotSpan(Buffer.CurrentSnapshot, vendor.Colon.AfterEnd + quotes, vendor.AfterEnd - vendor.Colon.AfterEnd - (quotes * 2)); yield return(new TagSpan <TextMarkerTag>(vendorSpan, new TextMarkerTag("vendorhighlight"))); } SnapshotSpan s = tagSpan.Span; yield return(new TagSpan <TextMarkerTag>(s, new TextMarkerTag("vendorhighlight"))); yield break; } } } }
private MappingPointSnapshot(ITextSnapshot root, SnapshotPoint anchor, PointTrackingMode trackingMode, IBufferGraph graph) { //Anchor and root are expected to be from concurrent snapshots ITextSnapshot correspondingAnchorSnapshot = MappingHelper.FindCorrespondingSnapshot(root, anchor.Snapshot.TextBuffer); _root = root; if (correspondingAnchorSnapshot != null) { _anchor = anchor.TranslateTo(correspondingAnchorSnapshot, trackingMode); } else { _anchor = anchor; _unmappable = true; } _trackingMode = trackingMode; _graph = graph; }
public SnapshotPoint?MapDownToBuffer(SnapshotPoint position, PointTrackingMode trackingMode, ITextBuffer targetBuffer, PositionAffinity affinity) { if (position.Snapshot == null) { throw new ArgumentNullException("position"); } if (trackingMode < PointTrackingMode.Positive || trackingMode > PointTrackingMode.Negative) { throw new ArgumentOutOfRangeException("trackingMode"); } if (targetBuffer == null) { throw new ArgumentNullException("targetBuffer"); } if (affinity < PositionAffinity.Predecessor || affinity > PositionAffinity.Successor) { throw new ArgumentOutOfRangeException("affinity"); } ITextBuffer currentBuffer = position.Snapshot.TextBuffer; ITextSnapshot currentSnapshot = currentBuffer.CurrentSnapshot; int currentPosition = position.TranslateTo(currentSnapshot, trackingMode).Position; while (currentBuffer != targetBuffer) { IProjectionBufferBase projBuffer = currentBuffer as IProjectionBufferBase; if (projBuffer == null) { return(null); } IProjectionSnapshot projSnap = projBuffer.CurrentSnapshot; if (projSnap.SourceSnapshots.Count == 0) { return(null); } SnapshotPoint currentPoint = projSnap.MapToSourceSnapshot(currentPosition, affinity); currentPosition = currentPoint.Position; currentSnapshot = currentPoint.Snapshot; currentBuffer = currentSnapshot.TextBuffer; } return(new SnapshotPoint(currentSnapshot, currentPosition)); }
public SnapshotPoint? MapDownToInsertionPoint(SnapshotPoint position, PointTrackingMode trackingMode, Predicate<ITextSnapshot> match) { var snapshot = position.Snapshot; var buffer = snapshot.TextBuffer; int pos = position.TranslateTo(snapshot, trackingMode); while (!match(snapshot)) { var projBuffer = buffer as IProjectionBufferBase; if (projBuffer == null) { return null; } var projSnapshot = projBuffer.CurrentSnapshot; if (projSnapshot.SourceSnapshots.Count == 0) { return null; } var pt = projSnapshot.MapToSourceSnapshot(pos); pos = pt.Position; snapshot = pt.Snapshot; buffer = snapshot.TextBuffer; } return new SnapshotPoint(snapshot, pos); }
public SnapshotPoint?MapDownToBuffer(SnapshotPoint position, PointTrackingMode trackingMode, ITextBuffer targetBuffer, PositionAffinity affinity) { if (position.Snapshot is null) { throw new ArgumentException(); } if (targetBuffer is null) { throw new ArgumentNullException(nameof(targetBuffer)); } if (position.Snapshot.TextBuffer != TopBuffer) { return(null); } if (TopBuffer != targetBuffer) { return(null); } return(position.TranslateTo(targetBuffer.CurrentSnapshot, trackingMode)); }
public SnapshotPoint?MapUpToFirstMatch(SnapshotPoint point, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match, PositionAffinity affinity) { if (point.Snapshot is null) { throw new ArgumentException(); } if (match is null) { throw new ArgumentNullException(nameof(match)); } if (point.Snapshot.TextBuffer != TopBuffer) { return(null); } if (!match(TopBuffer.CurrentSnapshot)) { return(null); } return(point.TranslateTo(TopBuffer.CurrentSnapshot, trackingMode)); }
void Select(SnapshotPoint a, SnapshotPoint b) { // In case there were any edits, eg. user pressed DEL a = a.TranslateTo(wpfTextViewHost.TextView.TextSnapshot, PointTrackingMode.Negative); b = b.TranslateTo(wpfTextViewHost.TextView.TextSnapshot, PointTrackingMode.Negative); wpfTextViewHost.TextView.Selection.Mode = TextSelectionMode.Stream; var line1 = wpfTextViewHost.TextView.GetTextViewLineContainingBufferPosition(a); var line2 = wpfTextViewHost.TextView.GetTextViewLineContainingBufferPosition(b); wpfTextViewHost.TextView.Selection.Mode = TextSelectionMode.Stream; if (line1.Start <= line2.Start) { wpfTextViewHost.TextView.Selection.Select(new VirtualSnapshotPoint(line1.Start), new VirtualSnapshotPoint(line2.EndIncludingLineBreak)); } else { wpfTextViewHost.TextView.Selection.Select(new VirtualSnapshotPoint(line1.EndIncludingLineBreak), new VirtualSnapshotPoint(line2.Start)); } wpfTextViewHost.TextView.Caret.MoveTo(wpfTextViewHost.TextView.Selection.ActivePoint); wpfTextViewHost.TextView.Caret.EnsureVisible(); }
public SnapshotPoint?MapDownToInsertionPoint(SnapshotPoint position, PointTrackingMode trackingMode, Predicate <ITextSnapshot> match) { if (position.Snapshot is null) { throw new ArgumentException(); } if (match is null) { throw new ArgumentNullException(nameof(match)); } if (position.Snapshot.TextBuffer != TopBuffer) { return(null); } if (!match(TopBuffer.CurrentSnapshot)) { return(null); } return(position.TranslateTo(TopBuffer.CurrentSnapshot, trackingMode)); }
ITextViewLine GetLine(SnapshotPoint bufferPosition, PositionAffinity affinity) { bufferPosition = bufferPosition.TranslateTo(textView.TextSnapshot, GetPointTrackingMode(affinity)); var line = textView.GetTextViewLineContainingBufferPosition(bufferPosition); if (line == null) return null; if (affinity == PositionAffinity.Successor) return line; if (line.Start.Position == 0 || line.Start != bufferPosition) return line; if (bufferPosition.GetContainingLine().Start == bufferPosition) return line; return textView.GetTextViewLineContainingBufferPosition(bufferPosition - 1); }
internal static SourceLocation TranslateIndex(int index, ITextSnapshot fromSnapshot, ModuleAnalysis toAnalysisSnapshot) { SnapshotCookie snapshotCookie; // TODO: buffers differ in the REPL window case, in the future we should handle this better if (toAnalysisSnapshot != null && fromSnapshot != null && (snapshotCookie = toAnalysisSnapshot.AnalysisCookie as SnapshotCookie) != null && snapshotCookie.Snapshot != null && snapshotCookie.Snapshot.TextBuffer == fromSnapshot.TextBuffer) { var fromPoint = new SnapshotPoint(fromSnapshot, index); var fromLine = fromPoint.GetContainingLine(); var toPoint = fromPoint.TranslateTo(snapshotCookie.Snapshot, PointTrackingMode.Negative); var toLine = toPoint.GetContainingLine(); Debug.Assert(fromLine != null, "Unable to get 'from' line from " + fromPoint.ToString()); Debug.Assert(toLine != null, "Unable to get 'to' line from " + toPoint.ToString()); return new SourceLocation( toPoint.Position, (toLine != null ? toLine.LineNumber : fromLine != null ? fromLine.LineNumber : 0) + 1, index - (fromLine != null ? fromLine.Start.Position : 0) + 1 ); } else if (fromSnapshot != null) { var fromPoint = new SnapshotPoint(fromSnapshot, index); var fromLine = fromPoint.GetContainingLine(); return new SourceLocation( index, fromLine.LineNumber + 1, index - fromLine.Start.Position + 1 ); } else { return new SourceLocation(index, 1, 1); } }
public SnapshotPoint? MapDownToFirstMatch(SnapshotPoint position, PointTrackingMode trackingMode, Predicate<ITextSnapshot> match, PositionAffinity affinity) { if (position.Snapshot == null) throw new ArgumentException(); if (match == null) throw new ArgumentNullException(nameof(match)); if (position.Snapshot.TextBuffer != TopBuffer) return null; if (!match(TopBuffer.CurrentSnapshot)) return null; return position.TranslateTo(TopBuffer.CurrentSnapshot, trackingMode); }
public SnapshotPoint GetNearestPointInVisualSnapshot(SnapshotPoint editBufferPoint, ITextSnapshot targetVisualSnapshot, PointTrackingMode trackingMode) => editBufferPoint.TranslateTo(targetVisualSnapshot, trackingMode);
public SnapshotPoint GetNearestPointInVisualSnapshot(SnapshotPoint editBufferPoint, ITextSnapshot targetVisualSnapshot, PointTrackingMode trackingMode) { // editBufferPoint MUST be in the editBuffer according to the docs if ( editBufferPoint.Snapshot.TextBuffer != this.EditBuffer ) throw new InvalidOperationException("editBufferPoint is not on the edit buffer"); return editBufferPoint.TranslateTo(targetVisualSnapshot, PointTrackingMode.Positive); }
SnapshotSpan? FindNextResultCore(FindOptions options, SnapshotPoint startingPosition) { if (SearchString.Length == 0) return null; var snapshot = wpfTextView.TextSnapshot; startingPosition = startingPosition.TranslateTo(snapshot, PointTrackingMode.Negative); var searchRange = new SnapshotSpan(snapshot, 0, snapshot.Length); try { return textSearchService2.Find(searchRange, startingPosition, SearchString, options); } catch (ArgumentException) when ((options & FindOptions.UseRegularExpressions) != 0) { // Invalid regex string return null; } }