mirror of
https://github.com/KDE/konsole.git
synced 2025-12-26 08:48:02 -05:00
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:
committed by
Kurt Hindenburg
parent
4e0bcd4edb
commit
e8f7710180
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user