Do not count trailing empty cells on selections

When selecting, the last line gets an added newline if the characters
returned from copyLineToStream() are less than the cells selected on that
last line.

A weird behaviour was that after running:

printf '                   v\n'
printf '\e[KSELECT ME\n'
printf '\e[31m\e[Kselect me\n'
printf '\e[0m                   ^\n'

selecting "SELECT ME          " would add a newline, while
selecting "select me          " would not add a newline.

This is a side-effect of clearImage() resizing lines which end with
spaces with the default rendition, so selecting the "SELECT ME" line
would get a count of 9 characters, which would make selecting more than
the initial 9 characters add a newline, while the "select me" line would
have additional spaces with isRealCharacter == false and a non-default
rendition.

Solve it but making copyLineToStream() not count and not pass to
PlainTextDecoder trailing characters where isRealCharacter == false.
This commit is contained in:
Luis Javier Merino Morán
2022-05-18 18:19:37 +02:00
committed by Kurt Hindenburg
parent 4e0bcd4edb
commit e8f7710180

View File

@@ -1645,6 +1645,16 @@ int Screen::copyLineToStream(int line,
auto *data = _screenLines[screenLine].data();
int length = _screenLines.at(screenLine).count();
// Exclude trailing empty cells from count and don't bother processing them further.
// This is necessary because a newline gets added to the last line when
// the selection extends beyond the last character (last non-whitespace
// character when TrimTrailingWhitespace is true), so the returned
// count from this funtion must not include empty cells beyond that
// last character.
while (length > 0 && !data[length - 1].isRealCharacter) {
length--;
}
// Don't remove end spaces in lines that wrap
if (options.testFlag(TrimTrailingWhitespace) && ((_lineProperties.at(screenLine) & LINE_WRAPPED) == 0)) {
// ignore trailing white space at the end of the line