Browse Source

Fixed exception in syntax highlighter when slowly scrolling to the end of the document (so that the span stack is set for all but the last line).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3639 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
81364494d7
  1. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Gui/TextView.cs
  2. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Gui/TextView.cs

@ -269,6 +269,9 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -269,6 +269,9 @@ namespace ICSharpCode.AvalonEdit.Gui
void DisposeVisualLine(VisualLine visualLine)
{
if (newVisualLines != null && newVisualLines.Contains(visualLine)) {
throw new ArgumentException("Cannot dispose visual line because it is in construction!");
}
visualLine.IsDisposed = true;
foreach (TextLine textLine in visualLine.TextLines) {
textLine.Dispose();
@ -284,6 +287,7 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -284,6 +287,7 @@ namespace ICSharpCode.AvalonEdit.Gui
{
VerifyAccess();
foreach (VisualLine visualLine in allVisualLines) {
Debug.Assert(visualLine.IsDisposed == false);
int start = visualLine.FirstDocumentLine.LineNumber;
int end = visualLine.LastDocumentLine.LineNumber;
if (documentLineNumber >= start && documentLineNumber <= end)
@ -385,6 +389,7 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -385,6 +389,7 @@ namespace ICSharpCode.AvalonEdit.Gui
}
Size lastAvailableSize;
List<VisualLine> newVisualLines;
/// <summary>
/// Measure implementation.
@ -411,7 +416,7 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -411,7 +416,7 @@ namespace ICSharpCode.AvalonEdit.Gui
clippedPixelsOnTop = scrollOffset.Y - heightTree.GetVisualPosition(firstLineInView);
Debug.Assert(clippedPixelsOnTop >= 0);
List<VisualLine> newVisualLines = new List<VisualLine>();
newVisualLines = new List<VisualLine>();
var elementGeneratorsArray = elementGenerators.ToArray();
var lineTransformersArray = lineTransformers.ToArray();
@ -446,13 +451,16 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -446,13 +451,16 @@ namespace ICSharpCode.AvalonEdit.Gui
}
foreach (VisualLine line in allVisualLines) {
Debug.Assert(line.IsDisposed == false);
if (!newVisualLines.Contains(line))
DisposeVisualLine(line);
}
RemoveInlineObjectsNow();
allVisualLines = newVisualLines;
// visibleVisualLines = readonly copy of visual lines
visibleVisualLines = new ReadOnlyCollection<VisualLine>(newVisualLines.ToArray());
newVisualLines = null;
if (allVisualLines.Any(line => line.IsDisposed)) {
throw new InvalidOperationException("A visual line was disposed even though it is still in use.\n" +

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs

@ -113,9 +113,13 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -113,9 +113,13 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
base.OnHighlightStateChanged(line, lineNumber);
if (colorizer.currentLineEndOffset >= 0) {
colorizer.textView.Redraw(colorizer.currentLineEndOffset,
colorizer.CurrentContext.Document.TextLength - colorizer.currentLineEndOffset,
DispatcherPriority.Normal);
int length = colorizer.CurrentContext.Document.TextLength - colorizer.currentLineEndOffset;
if (length != 0) {
// don't redraw if length == 0: at the end of the document, this would cause
// the last line which was already constructed to be redrawn ->
// we would get an exception due to disposing the line that was already constructed
colorizer.textView.Redraw(colorizer.currentLineEndOffset, length, DispatcherPriority.Normal);
}
colorizer.currentLineEndOffset = -1;
}
}

Loading…
Cancel
Save