summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-01 18:14:08 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-01 18:14:08 +0200
commit438a14c597c49df6238ae64b2869cca3d59aa142 (patch)
tree058115f0f7e83a92b9720b910f256b9092e533ed /Applications
parent33ac0de988c4328c3ed292190cbc38210e5f8c5f (diff)
downloadserenity-438a14c597c49df6238ae64b2869cca3d59aa142.zip
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. :^)
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Terminal/Terminal.cpp14
-rw-r--r--Applications/Terminal/Terminal.h3
2 files changed, 15 insertions, 2 deletions
diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp
index cf4c6812d7..85579225b0 100644
--- a/Applications/Terminal/Terminal.cpp
+++ b/Applications/Terminal/Terminal.cpp
@@ -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();
diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h
index 037bf37800..c0243419ee 100644
--- a/Applications/Terminal/Terminal.h
+++ b/Applications/Terminal/Terminal.h
@@ -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;