diff --git a/src/ScintillaNET/Scintilla.cs b/src/ScintillaNET/Scintilla.cs index d71b722..fb571ce 100644 --- a/src/ScintillaNET/Scintilla.cs +++ b/src/ScintillaNET/Scintilla.cs @@ -827,7 +827,7 @@ protected override void Dispose(bool disposing) /// 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(); } @@ -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; + } + } + /// /// Gets or sets the size of the dots used to mark whitespace. ///