From 737137cf7827fac685ab3c5f3d032de580fe764d Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 19 Oct 2024 15:53:18 +0200 Subject: [PATCH] Fixes Fl_Text_Display line number calculation. (#1088) --- FL/Fl_Text_Display.H | 5 ++++- src/Fl_Text_Display.cxx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index b5625d04d..533839a04 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -572,7 +572,10 @@ protected: int mCursorPreferredXPos; /* Pixel position for vert. cursor movement */ int mNVisibleLines; /* # of visible (displayed) lines. This is also the size of the mLineStarts[] array. */ - int mNBufferLines; /* # of newlines in the buffer */ + int mNBufferLines; /* # of newlines in the buffer, or number of + wraps if line wrapping is enabled. Note that + partial lines at the end of the buffer are + not counted, so you may want to add 1. */ Fl_Text_Buffer* mBuffer; /* Contains text to be displayed */ Fl_Text_Buffer* mStyleBuffer; /* Optional parallel buffer containing color and font information */ diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index ca0f7e6a2..c1f575b1b 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -702,7 +702,7 @@ void Fl_Text_Display::recalc_display() { scroll_(mTopLineNumHint, mHorizOffsetHint); // everything will fit in the viewport - if (mNBufferLines < mNVisibleLines || mBuffer == NULL || mBuffer->length() == 0) { + if ((mNBufferLines+1 < mNVisibleLines) || (mBuffer == NULL) || (mBuffer->length() == 0)) { scroll_(1, mHorizOffset); /* if empty lines become visible, there may be an opportunity to display more text by scrolling down */