From 87e81bce484fcfb014aa3cc324c236f949196ffa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 1 Sep 2025 17:26:52 +0200 Subject: [PATCH] Use number of displayed, and not document, lines in the map code We really care about the number of physical, i.e. "display", lines appearing in the window and not the number of logical, or "document", lines. They are the same as long as no lines are either wrapped or folded but become different as soon as either of them is used. --- samples/stc/stctest.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 9a76b15d92..5043d76c17 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -1045,6 +1045,13 @@ private: m_editVisibleLines = m_edit->LinesOnScreen(); } + // Get the total number of displayed lines, i.e. not taking hidden lines + // (due to folding) into account and counting wrapped lines. + int GetDisplayedLineCount() const + { + return VisibleFromDocLine(GetLineCount()); + } + // Get map line at the given mouse position. int GetMapLineAtPoint(const wxPoint& pos) const { @@ -1058,7 +1065,7 @@ private: if ( firstLine < 0 ) return 0; - auto const lastValid = GetLineCount() - m_editVisibleLines; + auto const lastValid = GetDisplayedLineCount() - m_editVisibleLines; if ( firstLine > lastValid ) return lastValid; @@ -1106,7 +1113,7 @@ private: // Scroll the editor to correspond to the current position in the map. void SyncEditPosition() { - auto const totalLines = GetLineCount(); + auto const totalLines = GetDisplayedLineCount(); if ( m_editVisibleLines >= totalLines ) { @@ -1128,7 +1135,7 @@ private: void SyncMapPosition() { // First check for the special case when all lines are visible. - auto const totalLines = GetLineCount(); + auto const totalLines = GetDisplayedLineCount(); if ( m_editVisibleLines >= totalLines ) { SetMapFirstVisibleLine(0); @@ -1295,7 +1302,7 @@ private: // mapFirst = α * editorFirst, we can compute the new editor first // line as thumbTopPos / ((1 - α) * mapLineHeight) or the map first // line as thumbTopPos / ((1/α - 1) * mapLineHeight). - auto const totalLines = GetLineCount(); + auto const totalLines = GetDisplayedLineCount(); SetEditFirstVisibleLine (