Browse Source

Fixed bug introduced in b7b12d310e (Reduce memory usage when dealing with long lines and word-wrapping)

4.0
Daniel Grunwald 15 years ago
parent
commit
b4f6f3a435
  1. 16
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/LinkElementGenerator.cs
  2. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs
  3. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs
  4. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/StringSegment.cs

16
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/LinkElementGenerator.cs

@ -57,25 +57,29 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -57,25 +57,29 @@ namespace ICSharpCode.AvalonEdit.Rendering
this.RequireControlModifierForClick = options.RequireControlModifierForHyperlinkClick;
}
Match GetMatch(int startOffset)
Match GetMatch(int startOffset, out int matchOffset)
{
int endOffset = CurrentContext.VisualLine.LastDocumentLine.EndOffset;
StringSegment relevantText = CurrentContext.GetText(startOffset, endOffset - startOffset);
return linkRegex.Match(relevantText.Text, relevantText.Offset, relevantText.Count);
Match m = linkRegex.Match(relevantText.Text, relevantText.Offset, relevantText.Count);
matchOffset = m.Success ? m.Index - relevantText.Offset + startOffset : -1;
return m;
}
/// <inheritdoc/>
public override int GetFirstInterestedOffset(int startOffset)
{
Match m = GetMatch(startOffset);
return m.Success ? startOffset + m.Index : -1;
int matchOffset;
GetMatch(startOffset, out matchOffset);
return matchOffset;
}
/// <inheritdoc/>
public override VisualLineElement ConstructElement(int offset)
{
Match m = GetMatch(offset);
if (m.Success && m.Index == 0) {
int matchOffset;
Match m = GetMatch(offset, out matchOffset);
if (m.Success && matchOffset == offset) {
Uri uri = GetUriFromMatch(m);
if (uri == null)
return null;

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs

@ -62,9 +62,8 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -62,9 +62,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
DocumentLine endLine = CurrentContext.VisualLine.LastDocumentLine;
StringSegment relevantText = CurrentContext.GetText(startOffset, endLine.EndOffset - startOffset);
int endPos = relevantText.Offset + relevantText.Count;
for (int i = relevantText.Offset; i < endPos; i++) {
char c = relevantText.Text[i];
for (int i = 0; i < relevantText.Count; i++) {
char c = relevantText.Text[relevantText.Offset + i];
switch (c) {
case ' ':
if (ShowSpaces)

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs

@ -137,8 +137,14 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -137,8 +137,14 @@ namespace ICSharpCode.AvalonEdit.Rendering
askInterestOffset = 0;
offset += element.DocumentLength;
if (offset > currentLineEnd) {
LastDocumentLine = document.GetLineByOffset(offset);
currentLineEnd = LastDocumentLine.Offset + LastDocumentLine.Length;
DocumentLine newEndLine = document.GetLineByOffset(offset);
if (newEndLine == this.LastDocumentLine) {
throw new InvalidOperationException(
"The VisualLineElementGenerator " + g.GetType().Name +
" produced an element which ends within the line delimiter");
}
currentLineEnd = newEndLine.Offset + newEndLine.Length;
this.LastDocumentLine = newEndLine;
}
break;
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/StringSegment.cs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;

Loading…
Cancel
Save