Terminal: Track which character cells have had something printed in them.

This helps us figure out where lines end, which we need when computing the
selected text for copy-to-clipboard. :^)
This commit is contained in:
Andreas Kling 2019-07-01 18:14:08 +02:00
parent 33ac0de988
commit 438a14c597
Notes: sideshowbarker 2024-07-19 13:24:47 +09:00
2 changed files with 15 additions and 2 deletions
Applications/Terminal

View file

@ -751,6 +751,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
auto& line = this->line(row);
line.characters[column] = ch;
line.attributes[column] = m_current_attribute;
line.attributes[column].flags |= Attribute::Touched;
line.dirty = true;
m_last_char = ch;
@ -1266,8 +1267,17 @@ String Terminal::selected_text() const
for (int row = start.row(); row <= end.row(); ++row) {
int first_column = row == start.row() ? start.column() : 0;
int last_column = row == end.row() ? end.column() : m_columns - 1;
for (int column = first_column; column <= last_column; ++column)
builder.append(line(row).characters[column]);
for (int column = first_column; column <= last_column; ++column) {
auto& line = this->line(row);
if (line.attributes[column].is_untouched()) {
builder.append('\n');
break;
}
builder.append(line.characters[column]);
if (column == line.m_length - 1) {
builder.append('\n');
}
}
}
return builder.to_string();

View file

@ -160,8 +160,11 @@ private:
Underline = 0x04,
Negative = 0x08,
Blink = 0x10,
Touched = 0x20,
};
bool is_untouched() const { return !(flags & Touched); }
// TODO: it would be really nice if we had a helper for enums that
// exposed bit ops for class enums...
int flags = Flags::NoAttributes;