Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Use the correct upper bound when clamping the display line #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/ScintillaNET/Scintilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ protected override void Dispose(bool disposing)
/// <seealso cref="Line.DisplayIndex" />
public int DocLineFromVisible(int displayLine)
{
displayLine = Helpers.Clamp(displayLine, 0, Lines.Count);
displayLine = Helpers.Clamp(displayLine, 0, VisibleLineCount);
return DirectMessage(NativeMethods.SCI_DOCLINEFROMVISIBLE, new IntPtr(displayLine)).ToInt32();
}

Expand Down Expand Up @@ -5313,6 +5313,31 @@ public bool VScrollBar
}
}

private int VisibleLineCount
{
get
{
bool wordWrapDisabled = WrapMode == WrapMode.None;
bool allLinesVisible = Lines.AllLinesVisible;

if (wordWrapDisabled && allLinesVisible)
{
return Lines.Count;
}

int count = 0;
for (int i = 0; i < Lines.Count; i++)
{
if (allLinesVisible || this.Lines[i].Visible)
{
count += wordWrapDisabled ? 1 : this.Lines[i].WrapCount;
}
}

return count;
}
}

/// <summary>
/// Gets or sets the size of the dots used to mark whitespace.
/// </summary>
Expand Down