Browse Source

Fix "InvalidOperationException: Trying to build visual line from collapsed line":

When the last line in the document was collapsed, the method HeightTree.GetNodeByVisualPosition(position after end of document)
was returning the last line in the document, when it should have returned the last non-collapsed line.

Also fixed a minor bug in FoldingMargin (missing end marker when folding starts above viewport and ends on last line of document).
pull/787/head
Daniel Grunwald 14 years ago
parent
commit
28c2f38f4f
  1. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingMargin.cs
  2. 40
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingMargin.cs

@ -222,7 +222,7 @@ namespace ICSharpCode.AvalonEdit.Folding @@ -222,7 +222,7 @@ namespace ICSharpCode.AvalonEdit.Folding
int maxEndOffset = 0;
foreach (FoldingSection fs in foldings) {
int end = fs.EndOffset;
if (end < viewEndOffset && !fs.IsFolded) {
if (end <= viewEndOffset && !fs.IsFolded) {
int textLineNr = GetTextLineIndexFromOffset(allTextLines, end);
if (textLineNr >= 0) {
endMarker[textLineNr] = foldingControlPen;

40
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs

@ -425,26 +425,34 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -425,26 +425,34 @@ namespace ICSharpCode.AvalonEdit.Rendering
HeightTreeNode GetNodeByVisualPosition(double position)
{
if (position <= 0) {
return root.LeftMost;
}
if (position > root.totalHeight) {
return root.RightMost;
}
HeightTreeNode node = root;
while (true) {
if (node.left != null && position < node.left.totalHeight) {
node = node.left;
} else {
if (node.left != null) {
position -= node.left.totalHeight;
double positionAfterLeft = position;
if (node.left != null) {
positionAfterLeft -= node.left.totalHeight;
if (positionAfterLeft < 0) {
// Descend into left
node = node.left;
continue;
}
position -= node.lineNode.TotalHeight;
if (position < 0 || node.right == null)
}
double positionBeforeRight = positionAfterLeft - node.lineNode.TotalHeight;
if (positionBeforeRight < 0) {
// Found the correct node
return node;
}
if (node.right == null || node.right.totalHeight == 0) {
// Can happen when position>node.totalHeight,
// i.e. at the end of the document, or due to rounding errors in previous loop iterations.
// If node.lineNode isn't collapsed, return that.
if (node.lineNode.TotalHeight > 0)
return node;
// node.right==null can happen when totalHeight is incorrect due to rounding errors,
// so position can be below the rounded totalHeight but larger than the sum
// of all nodes
// Otherwise, descend into left (find the last non-collapsed node)
node = node.left;
} else {
// Descend into right
position = positionBeforeRight;
node = node.right;
}
}

Loading…
Cancel
Save