Skip to content

Commit be6183d

Browse files
committed
fix(TextView): Clamp FirstVisibleLine
instead of effectively displaying nothing
1 parent 02a2aca commit be6183d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Project/Src/Gui/TextView.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public int FirstVisibleLine
4343
get => textArea.Document.GetFirstLogicalLine(textArea.VirtualTop.Y/FontHeight);
4444
set
4545
{
46-
if (FirstVisibleLine != value)
47-
textArea.VirtualTop = new Point(textArea.VirtualTop.X, textArea.Document.GetVisibleLine(value)*FontHeight);
46+
// Clamp the value in order to avoid scrolling the text out of view
47+
int clampedValue = Math.Max(0, Math.Min(value, textArea.Document.TotalNumberOfLines - textArea.TextView.VisibleLineCount + 1));
48+
if (FirstVisibleLine != clampedValue)
49+
textArea.VirtualTop = new Point(textArea.VirtualTop.X, textArea.Document.GetVisibleLine(clampedValue) * FontHeight);
4850
}
4951
}
5052

0 commit comments

Comments
 (0)