private int CalcCurrentParameter(SnapshotPoint triggerPt) { if (_params.Count == 0) { _currentParam = null; return(-1); } var source = _applicableToSpan.GetText(triggerPt.Snapshot); var localTriggerPos = triggerPt.Position - _applicableToSpan.GetStartPoint(triggerPt.Snapshot); var parser = new CodeParser(source); parser.ReadExact('('); // Skip past opening bracket var commaCount = 0; while (parser.Position < localTriggerPos && parser.ReadNestable()) { if (parser.Text == ",") { commaCount++; } } return(commaCount < _params.Count ? commaCount : _params.Count - 1); }
public void Invoke() { var classPicker = new ClassPicker(_snapshot.GetProject(GaugePackage.DTE)); var selectedClass = string.Empty; classPicker.ShowModal(); selectedClass = classPicker.SelectedClass; var containingLine = _trackingSpan.GetStartPoint(_snapshot).GetContainingLine(); if (_project.GetStepImplementation(containingLine) != null || selectedClass == null) { return; } CodeClass targetClass; CodeFunction implementationFunction; var gotImplementation = _stepImplementationGenerator.TryGenerateMethodStub(selectedClass, containingLine, out targetClass, out implementationFunction); if (!gotImplementation) { return; } _project.RefreshImplementations(); Project.NavigateToFunction(implementationFunction); _unimplementedStepTagger.MarkTagImplemented(_span); IsEnabled = false; }
/// <summary> /// Check if the property name in the text buffer has changed. /// If so, then dismiss the syntax help tip. /// </summary> private void OnTextBufferChanged(object sender, TextContentChangedEventArgs eventArgs) { if (_trackingSpan != null && _session != null) { ITextSnapshot snapshot = _trackingSpan.TextBuffer.CurrentSnapshot; SnapshotPoint startPoint = _trackingSpan.GetStartPoint(snapshot); bool propertyNameStillValid = false; if (startPoint.Position + _propertyName.Length <= snapshot.Length) { // Get the current text at the beginning of the tracking span. string text = snapshot.GetText(startPoint.Position, _propertyName.Length); char afterText = (startPoint.Position + _propertyName.Length < snapshot.Length) ? snapshot.GetText(startPoint.Position + _propertyName.Length, 1)[0] : '\0'; if (string.Equals(text, _propertyName, StringComparison.OrdinalIgnoreCase) && !char.IsLetterOrDigit(afterText) && afterText != '-') { // The correct property name is still in the code propertyNameStillValid = true; } } if (!propertyNameStillValid) { _session.Dismiss(); } } }
private void SaveCurrentTrackingData(Region sourceLocation) { try { if (!IsTracking()) { return; } ITextSnapshot textSnapshot = _trackingSpan.TextBuffer.CurrentSnapshot; SnapshotPoint startPoint = _trackingSpan.GetStartPoint(textSnapshot); SnapshotPoint endPoint = _trackingSpan.GetEndPoint(textSnapshot); var startLine = startPoint.GetContainingLine(); var endLine = endPoint.GetContainingLine(); var textLineStart = _textView.GetTextViewLineContainingBufferPosition(startPoint); var textLineEnd = _textView.GetTextViewLineContainingBufferPosition(endPoint); sourceLocation.StartColumn = startLine.Start.Position - textLineStart.Start.Position; sourceLocation.EndColumn = endLine.End.Position - textLineEnd.Start.Position; sourceLocation.StartLine = startLine.LineNumber + 1; sourceLocation.EndLine = endLine.LineNumber + 1; } catch (InvalidOperationException) { // Editor throws InvalidOperationException in some cases - // We act like tracking isn't turned on if this is thrown to avoid // taking all of VS down. } }
/// <inheritdoc /> public void Commit() { if (!session.SelectedCompletionSet.SelectionStatus.IsSelected) { return; } ITrackingSpan applicableTo = session.SelectedCompletionSet.ApplicableTo; using (ITextEdit edit = applicableTo.TextBuffer.CreateEdit()) { // The insertion text is inserted without the \xFF character (if any) string insertionText = InsertionText.Replace("\xFF", ""); edit.Replace(applicableTo.GetSpan(edit.Snapshot), insertionText); ITextSnapshot applied = edit.Apply(); // The original position of the \xFF character determines the placement of the caret int caretOffset = InsertionText.IndexOf('\xFF'); if (caretOffset >= 0) { SnapshotPoint startPoint = applicableTo.GetStartPoint(applied); SnapshotPoint caretPoint = startPoint + caretOffset; session.TextView.Caret.MoveTo(caretPoint, PositionAffinity.Predecessor); } } }
public Task <object> GetPreviewAsync(CancellationToken cancellationToken) { var snapShot = _span.TextBuffer.CurrentSnapshot; var theSpan = _span.GetSpan(snapShot); var line = snapShot.GetLineFromPosition(_span.GetStartPoint(snapShot).Position); SnapshotSpan preSpan = new SnapshotSpan(line.Start, theSpan.Start); SnapshotSpan postSpan = new SnapshotSpan(theSpan.End, line.End); var textBlock = new TextBlock(); textBlock.Padding = new Thickness(5); textBlock.Inlines.Add(new Run() { Text = preSpan.GetText() }); textBlock.Inlines.Add(new Run() { Text = _fixedCode, Foreground = new SolidColorBrush(Color.FromRgb(0x34, 0xAF, 0x00)) }); textBlock.Inlines.Add(new Run() { Text = postSpan.GetText() }); return(Task.FromResult <object>(textBlock)); }
internal void computeCurrentParameter() { //AsmDudeToolsStatic.Output("INFO: AsmSignatureHelpSource: computeCurrentParameter"); int nParameters = this.Parameters.Count; if (nParameters == 0) { this.CurrentParameter = null; return; } //the number of commas in the current line is the index of the current parameter SnapshotPoint position = _applicableToSpan.GetStartPoint(_subjectBuffer.CurrentSnapshot); string lineStr = _subjectBuffer.CurrentSnapshot.GetLineFromPosition(position).GetText(); //AsmDudeToolsStatic.Output("INFO: AsmSignatureHelpSource: computeCurrentParameter. lineStr=" + lineStr); int commaCount = AsmSignature.countCommas(lineStr); //AsmDudeToolsStatic.Output("INFO: AsmSignatureHelpSource: computeCurrentParameter. commaCount="+ commaCount); if (commaCount < nParameters) { this.CurrentParameter = this.Parameters[commaCount]; } else { this.CurrentParameter = null; } }
public void Invoke() { if (AttachablesPackage.Manager != null) { try { var line = m_span.GetEndPoint(m_snapshot).GetContainingLine(); var text = line.Extent.GetText(); text = text.Trim(); var match = TodoTagger.todoLineRegex.Match(text); text = text.Substring(match.Index + match.Length); var reminder = AttachablesPackage.Manager.AttachReminder(text.Trim(), m_path, FileLocation, line.LineNumber); ITrackingPoint triggerPoint = m_snapshot.CreateTrackingPoint( m_span.GetStartPoint(m_snapshot), PointTrackingMode.Positive); AttachablesPackage.Manager.TrackReminder(triggerPoint, m_view, reminder); m_enabled = false; this.m_tagger.RaiseTagsChanged(m_span.GetSpan(m_snapshot)); } catch (Exception ex) { Trace.WriteLine(ex.Message); } } }
/// <summary> /// Check if the property name in the text buffer has changed. /// If so, then dismiss the syntax help tip. /// </summary> private void OnTextBufferChanged(object sender, TextContentChangedEventArgs eventArgs) { if (_trackingSpan != null && _session != null) { ITextSnapshot snapshot = _trackingSpan.TextBuffer.CurrentSnapshot; SnapshotPoint startPoint = _trackingSpan.GetStartPoint(snapshot); bool propertyNameStillValid = false; if (startPoint.Position + _propertyName.Length <= snapshot.Length) { string text = _trackingSpan.GetText(snapshot); if (text.StartsWith("[", StringComparison.Ordinal)) { // The correct property name is still in the code propertyNameStillValid = true; _session.Match(); } } if (!propertyNameStillValid) { _session.Dismiss(); } } }
private bool IsExtentTokenExpected(SnapshotSpan range, TextExtent extent, out ITrackingSpan trackSpan, out PSharpParser parser) { string extentText = extent.Span.GetText(); var extentToken = string.IsNullOrWhiteSpace(extentText) ? null : new PSharpLexer().Tokenize(extentText).FirstOrDefault(); if (extentToken == null) { trackSpan = null; parser = null; return(false); } // TODO: Minimize the re-parse span for speed. var snapshot = extent.Span.Snapshot; trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start, trackSpan.GetStartPoint(snapshot).Position)); var tokens = new PSharpLexer().Tokenize(preSpan.GetText()); parser = new PSharpParser(ParsingOptions.CreateForVsLanguageService()); try { parser.ParseTokens(tokens); } catch (ParsingException) { // Parsing exception is expected } return(this.IsExpectedTokenType(extentToken, parser.GetExpectedTokenTypes())); }
public static SpanInfo CreateFromBuffer(ITrackingSpan span) { return(new SpanInfo() { Span = span, Start = span.GetStartPoint(span.TextBuffer.CurrentSnapshot), End = span.GetEndPoint(span.TextBuffer.CurrentSnapshot) }); }
/// <summary> /// Initializes a new instance of the <see cref="ReplacementEdit"/> class. /// </summary> /// <param name="replacement">The SARIF replacement from which to construct the edit.</param> /// <param name="snapshot">The snapshot to which the edit will be applied.</param> public ReplacementEdit(ReplacementModel replacement, ITextSnapshot snapshot) { this.Text = replacement.InsertedString ?? string.Empty; ITrackingSpan replacementSpan = replacement.PersistentSpan.Span; SnapshotPoint start = replacementSpan.GetStartPoint(snapshot); SnapshotPoint end = replacementSpan.GetEndPoint(snapshot); this.Span = new SnapshotSpan(start, end); }
private void ComputeApplicableToSpan(IEnumerable <ITrackingSpan> applicableToSpans) { // Requires UI thread for access to BufferGraph. IntellisenseUtilities.ThrowIfNotOnMainThread(this.JoinableTaskContext); ITrackingSpan newApplicableToSpan = Volatile.Read(ref this.applicableToSpan); foreach (var result in applicableToSpans) { var applicableToSpan = result; if (applicableToSpan != null) { SnapshotSpan subjectAppSnapSpan = applicableToSpan.GetSpan(applicableToSpan.TextBuffer.CurrentSnapshot); var surfaceAppSpans = this.TextView.BufferGraph.MapUpToBuffer( subjectAppSnapSpan, applicableToSpan.TrackingMode, this.TextView.TextBuffer); if (surfaceAppSpans.Count >= 1) { applicableToSpan = surfaceAppSpans[0].Snapshot.CreateTrackingSpan(surfaceAppSpans[0], applicableToSpan.TrackingMode); newApplicableToSpan = IntellisenseUtilities.GetEncapsulatingSpan( this.TextView, newApplicableToSpan, applicableToSpan); } } } // Scope the applicableToSpan down to just the current line to ensure that interactions // with interactive controls such as lightbulb are not impeded by the tip appearing // far away from the mouse. if (newApplicableToSpan != null) { var currentSnapshot = newApplicableToSpan.TextBuffer.CurrentSnapshot; var spanStart = newApplicableToSpan.GetStartPoint(currentSnapshot); var spanEnd = newApplicableToSpan.GetEndPoint(currentSnapshot); var triggerPointLine = this.triggerPoint.GetPoint(currentSnapshot).GetContainingLine(); var triggerPointLineExtent = triggerPointLine.Extent; var newStart = Math.Max(triggerPointLineExtent.Start, spanStart); var newEnd = Math.Min(triggerPointLineExtent.End, spanEnd); if (newStart <= newEnd) { newApplicableToSpan = currentSnapshot.CreateTrackingSpan(Span.FromBounds(newStart, newEnd), SpanTrackingMode.EdgeInclusive); } } Volatile.Write(ref this.applicableToSpan, newApplicableToSpan); }
private void Tokenize(ITrackingSpan spanToTokenize, string spanText) { Log.Debug("Parsing input."); ParseError[] errors; _generatedAst = Parser.ParseInput(spanText, out _generatedTokens, out errors); var position = spanToTokenize.GetStartPoint(Buffer.CurrentSnapshot).Position; var array = _generatedTokens; Log.Debug("Classifying tokens."); _tokenSpans = _classifierService.ClassifyTokens(array, position); Log.Debug("Tagging error spans."); _errorTags = _errorTagService.TagErrorSpans(Buffer, position, errors).ToList(); Log.Debug("Matching braces and regions."); _regionAndBraceMatchingService.GetRegionsAndBraceMatchingInformation(spanText, position, _generatedTokens, out _startBraces, out _endBraces, out _regions); }
void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { //get tracking span ITrackingSpan trackingSpan = FindTokenSpanAtPosition(session.GetTriggerPoint(_textBuffer), session); //find current indent ITextSnapshot snapshot = session.TextView.TextSnapshot; SnapshotPoint currentPoint = trackingSpan.GetStartPoint(snapshot); ITextSnapshotLine snapshotLine = snapshot.GetLineFromPosition(currentPoint); string wordText = trackingSpan.GetText(snapshot); string lineText = snapshotLine.GetText(); int lineStartPos = snapshotLine.Start.Position; int lineEndPos = snapshotLine.End.Position; int currentPos = currentPoint.Position; int indent = currentPos - lineStartPos; if (wordText == ".") { indent++; } //build completion list List <Completion> completionList = new List <Completion>(); //insert snippets foreach (Snippet snippet in Session.Current.Settings.Snippets) { completionList.Add(new SnippetCompletion(snippet, indent)); } //add completion set if it contains any entries if (completionList.Count > 0) { completionSets.Add(new CompletionSet( "Snippets", //the non-localized title of the tab "Snippets", //the display title of the tab trackingSpan, completionList, null)); } }
internal static MissingImportAnalysis GetMissingImports(ITextSnapshot snapshot, ITrackingSpan span) { ReverseExpressionParser parser = new ReverseExpressionParser(snapshot, snapshot.TextBuffer, span); var loc = span.GetSpan(snapshot.Version); int dummy; SnapshotPoint? dummyPoint; string lastKeywordArg; bool isParameterName; var exprRange = parser.GetExpressionRange(0, out dummy, out dummyPoint, out lastKeywordArg, out isParameterName); if (exprRange == null || isParameterName) { return MissingImportAnalysis.Empty; } var analysis = ((IPythonProjectEntry)snapshot.TextBuffer.GetProjectEntry()).Analysis; if (analysis == null) { return MissingImportAnalysis.Empty; } var text = exprRange.Value.GetText(); var analyzer = analysis.ProjectState; var index = span.GetStartPoint(snapshot).Position; var expr = Statement.GetExpression( analysis.GetAstFromTextByIndex( text, TranslateIndex( index, snapshot, analysis ) ).Body ); if (expr != null && expr is NameExpression) { var nameExpr = (NameExpression)expr; if (!IsImplicitlyDefinedName(nameExpr)) { var applicableSpan = parser.Snapshot.CreateTrackingSpan( exprRange.Value.Span, SpanTrackingMode.EdgeExclusive ); lock (snapshot.TextBuffer.GetAnalyzer()) { index = TranslateIndex( index, snapshot, analysis ); var variables = analysis.GetVariablesByIndex(text, index).Where(IsDefinition).Count(); var values = analysis.GetValuesByIndex(text, index).ToArray(); // if we have type information or an assignment to the variable we won't offer // an import smart tag. if (values.Length == 0 && variables == 0) { string name = nameExpr.Name; var imports = analysis.ProjectState.FindNameInAllModules(name); return new MissingImportAnalysis(imports, applicableSpan); } } } } // if we have type information don't offer to add imports return MissingImportAnalysis.Empty; }
public static ITrackingPoint GetStartTrackingPoint(this ITrackingSpan span, PointTrackingMode mode) { return(span.GetStartPoint(span.TextBuffer.CurrentSnapshot).CreateTrackingPoint(mode)); }
// This is called on a background thread. public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var triggerPoint = session.GetTriggerPoint(textBuffer.CurrentSnapshot); if (triggerPoint != null) { TextExtent extent = textStructureNavigator.GetExtentOfWord(triggerPoint.Value); SnapshotSpan extentSpan = extent.Span; ITextSnapshotLine line = triggerPoint.Value.GetContainingLine(); ITrackingSpan lineSpan = textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); try { if (debugger == null) { return(null); } var stackFrame = debugger.CurrentStackFrame; if (stackFrame == null) { return(null); } // Try to extent the span to the potential chain of member accesses on the left int lineStartPosition = lineSpan.GetStartPoint(textBuffer.CurrentSnapshot).Position; string lineText = lineSpan.GetText(textBuffer.CurrentSnapshot); int localPosition = extentSpan.Start.Position - lineStartPosition; while (localPosition > 1 && (lineText[localPosition - 1] == '.' || lineText[localPosition - 1] == ':')) { TextExtent leftExtent = textStructureNavigator.GetExtentOfWord(new SnapshotPoint(textBuffer.CurrentSnapshot, lineStartPosition + localPosition - 2)); SnapshotSpan leftExtentSpan = leftExtent.Span; if (leftExtentSpan.Start.Position >= lineStartPosition) { extentSpan = new SnapshotSpan(leftExtentSpan.Start, extentSpan.End.Position - leftExtentSpan.Start.Position); localPosition = leftExtentSpan.Start.Position - lineStartPosition; } } var expressionText = extentSpan.GetText(); // Switch to main thread to access properties await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var language = stackFrame.Language; if (language != "Lua") { return(null); } var expression = debugger.GetExpression3($"```{expressionText}", stackFrame, false, false, false, 500); if (expression == null) { return(null); } if (!expression.IsValidValue) { return(null); } string value = expression.Value; string type = ""; string name = ""; if (value.IndexOf("```") >= 0) { type = value.Substring(0, value.IndexOf("```")); value = value.Substring(value.IndexOf("```") + 3); } if (value.IndexOf("```") >= 0) { name = value.Substring(0, value.IndexOf("```")); value = value.Substring(value.IndexOf("```") + 3); } var element = new ContainerElement(ContainerElementStyle.Wrapped, new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Type, $"{type} "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, name), new ClassifiedTextRun(PredefinedClassificationTypeNames.String, $" = {value}"))); return(new QuickInfoItem(lineSpan, element)); } catch (Exception) { return(null); } } return(null); }
public SnapshotPoint GetStartPoint(ITextSnapshot snapshot) { return(_referenceSpan.GetStartPoint(snapshot)); }
public int GetStartPoint(IEditorBufferSnapshot snapshot) => _span.GetStartPoint(snapshot.As <ITextSnapshot>());
internal void ParamCurrentCalc() { if (m_session.IsDismissed == true || m_session == null) { return; } NSUtil.DebugPrintAlways("NSSig - ParamCurrentCalc"); if (m_parameters.Count == 0) { this.CurrentParameter = null; return; } //SnapshotPoint? point_trigger_null = m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot); SnapshotPoint point_trigger = (SnapshotPoint)m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot); var trigger_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_trigger.Position); SnapshotPoint point_curr2 = m_session.TextView.Caret.Position.BufferPosition; SnapshotPoint point_curr = (SnapshotPoint)m_session.TextView.BufferGraph.MapUpToBuffer( point_curr2, PointTrackingMode.Positive, PositionAffinity.Successor, m_subjectBuffer.CurrentSnapshot.TextBuffer); //if (!point_curr2.HasValue) return; //SnapshotPoint point_curr = point_curr2.Value; var curr_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_curr.Position); SnapshotPoint point_left = m_applicabletospan.GetStartPoint(m_subjectBuffer.CurrentSnapshot); string sig_str = m_applicabletospan.GetText(m_subjectBuffer.CurrentSnapshot); if (curr_linenum != trigger_linenum || point_curr < point_left) { m_session.Dismiss(); return; } SnapshotPoint point_test = point_curr - 1; int commas_count = 0; while (true) { if (point_test <= point_left) { break; } if (point_test.GetChar() == ',') { commas_count += 1; } if (point_test.GetChar() == ')') { m_session.Dismiss(); return; } point_test -= 1; } if (commas_count < m_parameters.Count) { this.CurrentParameter = m_parameters[commas_count]; } else { this.CurrentParameter = m_parameters[m_parameters.Count - 1]; } return; }
public void UpdateSelection(ITextView textView, ITextBuffer subjectBuffer, ITrackingSpan activeRenameSpan) { var snapshot = subjectBuffer.CurrentSnapshot; var anchor = new VirtualSnapshotPoint(snapshot, this.currentState.SelectionAnchorPoint + activeRenameSpan.GetStartPoint(snapshot)); var active = new VirtualSnapshotPoint(snapshot, this.currentState.SelectionActivePoint + activeRenameSpan.GetStartPoint(snapshot)); textView.SetSelection(anchor, active); }
public static int GetCurrentStart(this ITrackingSpan trackingSpan) { ITextSnapshot snapshot = trackingSpan.TextBuffer.CurrentSnapshot; return(trackingSpan.GetStartPoint(snapshot).Position); }
public ExpressionAnalysis AnalyzeExpression(ITextView view, ITextSnapshot snapshot, ITrackingSpan span, bool forCompletion = true) { AnalysisEntry entry; if (_entryService == null || !_entryService.TryGetAnalysisEntry(view, snapshot.TextBuffer, out entry)) { return(null); } return(entry.Analyzer.WaitForRequest(entry.Analyzer.AnalyzeExpressionAsync(entry, view, span.GetStartPoint(snapshot)), "AnalyzeExpression")); }
public ExpressionAnalysis AnalyzeExpression(ITextView view, ITextSnapshot snapshot, ITrackingSpan span, bool forCompletion = true) { var entry = view.GetAnalysisEntry(snapshot.TextBuffer, Site); return(entry.Analyzer.WaitForRequest(entry.Analyzer.AnalyzeExpressionAsync(entry, view, span.GetStartPoint(snapshot)), "AnalyzeExpression")); }
static bool IsAfterDot(ITextSnapshot snapshot, ITrackingSpan applicableToSpan) { var position = applicableToSpan.GetStartPoint(snapshot).Position; return(position > 0 && snapshot[position - 1] == '.'); }
/// <summary> /// Gets a ExpressionAnalysis for the expression at the provided span. If the span is in /// part of an identifier then the expression is extended to complete the identifier. /// </summary> public static Task <ExpressionAnalysis> AnalyzeExpressionAsync(this ITextSnapshot snapshot, IServiceProvider serviceProvider, ITrackingSpan span, bool forCompletion = true) { return(VsProjectAnalyzer.AnalyzeExpressionAsync(span.GetStartPoint(snapshot))); }
public ExpressionAnalysis AnalyzeExpression(ITextView view, ITextSnapshot snapshot, ITrackingSpan span, bool forCompletion = true) { return(VsProjectAnalyzer.AnalyzeExpressionAsync(_container, view, span.GetStartPoint(snapshot)).WaitOrDefault(1000)); }
void CalculateChange(TextContentChangedEventArgs e) { #if DEBUG Util.LogTextChanges(e.Changes); #endif if (_fullReparse == true) { return; } if (e.Changes.Count != 1) { _fullReparse = true; return; } ITextChange textChange = e.Changes[0]; if (_editSpan == null) { _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan( textChange.NewPosition, textChange.NewEnd - textChange.NewPosition, SpanTrackingMode.EdgeInclusive); #if DEBUG Util.Log("Created new edit span (" + _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," + _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ", _buffer.CurrentSnapshot.GetText( _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position, _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position - _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position)); #endif } else { int oldEditStartPosition = _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position; int oldEditEndPosition = _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position; // In many cases, new edit is auto-merged with old edit by tracking span. To be more' // specific, in all cases when new edit is adjacent to the old edit, it will be // auto-merged. We need to create a new tracking span only if the new edit was non-adjacent // to the old edit (i.e. a few characters before the old edit or a few characters after // the old edit). if (textChange.NewPosition < oldEditStartPosition || textChange.NewPosition > oldEditEndPosition) { int newEditStartPosition = Math.Min(textChange.NewPosition, oldEditStartPosition); int newEditEndPosition = Math.Max(textChange.NewEnd, oldEditEndPosition); _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan( newEditStartPosition, newEditEndPosition - newEditStartPosition, SpanTrackingMode.EdgeInclusive); } #if DEBUG Util.Log("Updated edit span (" + _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," + _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ", _buffer.CurrentSnapshot.GetText( _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position, _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position - _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position)); #endif } }