From b1098071ce146dfe3870a3ec4a25c68fd311efc9 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 6 May 2010 13:36:26 +0000 Subject: [PATCH] Fixed ArgumentException in TextView.Redraw when deleting line in XML document. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5766 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Highlighting/DocumentHighlighter.cs | 21 ++++++++++++++++++- .../Highlighting/HighlightingColorizer.cs | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs index c131d49962..b83161d7b4 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/DocumentHighlighter.cs @@ -179,7 +179,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting //Debug.WriteLine("Highlight line " + lineNumber + (highlightedLine != null ? "" : " (span stack only)")); spanStack = storedSpanStacks[lineNumber - 1]; HighlightLineInternal(line); - if (storedSpanStacks[lineNumber] != spanStack) { + if (!EqualSpanStacks(spanStack, storedSpanStacks[lineNumber])) { isValid[lineNumber] = true; //Debug.WriteLine("Span stack in line " + lineNumber + " changed from " + storedSpanStacks[lineNumber] + " to " + spanStack); storedSpanStacks[lineNumber] = spanStack; @@ -198,6 +198,25 @@ namespace ICSharpCode.AvalonEdit.Highlighting } } + static bool EqualSpanStacks(SpanStack a, SpanStack b) + { + // We must use value equality between the stacks because TextViewDocumentHighlighter.OnHighlightStateChanged + // depends on the fact that equal input state + unchanged line contents produce equal output state. + if (a == b) + return true; + if (a == null || b == null) + return false; + while (!a.IsEmpty && !b.IsEmpty) { + if (a.Peek() != b.Peek()) + return false; + a = a.Pop(); + b = b.Pop(); + if (a == b) + return true; + } + return a.IsEmpty && b.IsEmpty; + } + /// /// Is called when the highlighting state at the end of the specified line has changed. /// diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs index ee8df9d2a3..091f486658 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs @@ -218,7 +218,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting // We'll prove that: if line N is being reused, then the highlighting state is up-to-date until (end of) line N-1. - // Start of induction: the first line in view can is reused only if the highlighting state was up-to-date + // Start of induction: the first line in view is reused only if the highlighting state was up-to-date // until line N-1 (no change detected in VisualLineConstructionStarting event). // Induction step: