diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs index 77272ce29c..47b84b46f3 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/HeightTree.cs @@ -446,7 +446,8 @@ namespace ICSharpCode.AvalonEdit.Rendering // 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) + // Also return node.lineNode if there is no previous node that we could return instead. + if (node.lineNode.TotalHeight > 0 || node.left == null) return node; // Otherwise, descend into left (find the last non-collapsed node) node = node.left;