Commit e8f77101 authored by Luis Javier Merino's avatar Luis Javier Merino Committed by Kurt Hindenburg
Browse files

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.
parent 4e0bcd4e
Pipeline #179801 passed with stage
in 2 minutes and 33 seconds
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment