Skip to content

Commit 438a14c

Browse files
committed
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. :^)
1 parent 33ac0de commit 438a14c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Applications/Terminal/Terminal.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
751751
auto& line = this->line(row);
752752
line.characters[column] = ch;
753753
line.attributes[column] = m_current_attribute;
754+
line.attributes[column].flags |= Attribute::Touched;
754755
line.dirty = true;
755756

756757
m_last_char = ch;
@@ -1266,8 +1267,17 @@ String Terminal::selected_text() const
12661267
for (int row = start.row(); row <= end.row(); ++row) {
12671268
int first_column = row == start.row() ? start.column() : 0;
12681269
int last_column = row == end.row() ? end.column() : m_columns - 1;
1269-
for (int column = first_column; column <= last_column; ++column)
1270-
builder.append(line(row).characters[column]);
1270+
for (int column = first_column; column <= last_column; ++column) {
1271+
auto& line = this->line(row);
1272+
if (line.attributes[column].is_untouched()) {
1273+
builder.append('\n');
1274+
break;
1275+
}
1276+
builder.append(line.characters[column]);
1277+
if (column == line.m_length - 1) {
1278+
builder.append('\n');
1279+
}
1280+
}
12711281
}
12721282

12731283
return builder.to_string();

Applications/Terminal/Terminal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ class Terminal final : public GFrame {
160160
Underline = 0x04,
161161
Negative = 0x08,
162162
Blink = 0x10,
163+
Touched = 0x20,
163164
};
164165

166+
bool is_untouched() const { return !(flags & Touched); }
167+
165168
// TODO: it would be really nice if we had a helper for enums that
166169
// exposed bit ops for class enums...
167170
int flags = Flags::NoAttributes;

0 commit comments

Comments
 (0)