From 4d081f739add0fab9c4ef2aa822a417c242e207b Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Fri, 4 May 2018 16:58:56 -0700 Subject: Revert "Fix VSTS 609859." This reverts commit ff78c2e24e1e0a675d0c16d94e675e41f7aa5e36. --- .../VSEditor/TagBasedSyntaxHighlighting.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs index f3c9c1889c..48f4f3166f 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs @@ -49,8 +49,11 @@ namespace Microsoft.VisualStudio.Platform public async Task GetHighlightedLineAsync(IDocumentLine line, CancellationToken cancellationToken) { - ITextSnapshotLine snapshotLine = (line as Mono.TextEditor.TextDocument.DocumentLineFromTextSnapshotLine)?.Line; - if (this.classifier == null || snapshotLine == null || snapshotLine.Snapshot != snapshotLine.Snapshot.TextBuffer.CurrentSnapshot) + //TODO verify that the snapshot line from this.textBuffer is equivalent to the document line converted to a snapshotline. + //Possibly take in a TextDataModel as a parameter and verify the buffers are appropriate. + //ITextSnapshotLine snapshotLine = (line as Mono.TextEditor.TextDocument.DocumentLineFromTextSnapshotLine)?.Line; + ITextSnapshotLine snapshotLine = textBuffer.CurrentSnapshot.GetLineFromLineNumber (line.LineNumber - 1); + if ((this.classifier == null) || (snapshotLine == null)) { return new HighlightedLine(line, new[] { new ColoredSegment(0, line.Length, ScopeStack.Empty) }); } -- cgit v1.2.3 From 9eca7e7ce0d49becaaeb53fb705125ef4ed87b94 Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Fri, 4 May 2018 17:14:41 -0700 Subject: Surround the problematic code in TextViewMargin.SpanUpdateListener w try/catch. --- .../Gui/TextViewMargin.SpanUpdateListener.cs | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.SpanUpdateListener.cs b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.SpanUpdateListener.cs index f0700ee6ee..3bc3227d5a 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.SpanUpdateListener.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.SpanUpdateListener.cs @@ -75,10 +75,14 @@ namespace Mono.TextEditor void Document_TextChanging (object sender, TextChangeEventArgs e) { - HasUpdatedMultilineSpan = false; - foreach (var change in e.TextChanges) { - var layout = textEditor.TextViewMargin.GetLayout (textEditor.GetLineByOffset (change.Offset)); - lines.Add (layout.HighlightedLine); + try { + HasUpdatedMultilineSpan = false; + foreach (var change in e.TextChanges) { + var layout = textEditor.TextViewMargin.GetLayout (textEditor.GetLineByOffset (change.Offset)); + lines.Add (layout.HighlightedLine); + } + } + catch { } } @@ -86,15 +90,20 @@ namespace Mono.TextEditor { int i = 0; - foreach (var change in e.TextChanges) { - if (i >= lines.Count) - break; // should never happen - var oldHighlightedLine = lines [i++]; - var curLine = textEditor.GetLineByOffset (change.Offset); - var curLayout = textEditor.TextViewMargin.GetLayout (curLine); - if (!UpdateLineHighlight (curLine.LineNumber, oldHighlightedLine, curLayout.HighlightedLine)) - break; + try { + foreach (var change in e.TextChanges) { + if (i >= lines.Count) + break; // should never happen + var oldHighlightedLine = lines[i++]; + var curLine = textEditor.GetLineByOffset (change.Offset); + var curLayout = textEditor.TextViewMargin.GetLayout (curLine); + if (!UpdateLineHighlight (curLine.LineNumber, oldHighlightedLine, curLayout.HighlightedLine)) + break; + } + } + catch { } + lines.Clear (); } -- cgit v1.2.3