Fix trimming of trailing whitespace in Fl_Terminal::text()

... and document a missing parameter.
This commit is contained in:
Albrecht Schlosser 2024-03-12 17:37:42 +01:00
parent d30e4aa0af
commit aa02a0297b

View File

@ -3905,6 +3905,8 @@ int Fl_Terminal::handle(int e) {
free((void*)s); // free() the copy when done!
\endcode
\param[in] lines_below_cursor include lines below cursor, default: false
\return A string allocated with strdup(3) which must be free'd, text is UTF-8.
*/
const char* Fl_Terminal::text(bool lines_below_cursor) const {
@ -3922,8 +3924,8 @@ const char* Fl_Terminal::text(bool lines_below_cursor) const {
const char *s = u8c->text_utf8(); // first byte of char
for (int i=0; i<u8c->length(); i++) lines += *s++; // append all bytes in multibyte char
// Count any trailing whitespace to trim
if (u8c->length()==1 && *s==' ') trim++; // trailing whitespace? trim
else trim = 0; // non-whitespace? don't trim
if (u8c->length()==1 && s[-1]==' ') trim++; // trailing whitespace? trim
else trim = 0; // non-whitespace? don't trim
}
// trim trailing whitespace from each line, if any
if (trim) lines.resize(lines.size() - trim);