diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-22 19:59:27 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-22 19:59:27 +0200 |
commit | 1ca6adee901f715ac235a077d789e0eedd7f7c0e (patch) | |
tree | f7b69f670647479de5c0e49f6cbd2d20cd5ec631 /Applications | |
parent | fae379b1f081064b890147232c80550515e08678 (diff) | |
download | serenity-1ca6adee901f715ac235a077d789e0eedd7f7c0e.zip |
Terminal: Allow selecting words by double-clicking them
Bonus feature: also allow selecting the whitespace in-between words by
double-clicking that. :^)
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Terminal/TerminalWidget.cpp | 27 | ||||
-rw-r--r-- | Applications/Terminal/TerminalWidget.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Applications/Terminal/TerminalWidget.cpp b/Applications/Terminal/TerminalWidget.cpp index ad4be8cac4..b0ff28cf9e 100644 --- a/Applications/Terminal/TerminalWidget.cpp +++ b/Applications/Terminal/TerminalWidget.cpp @@ -369,6 +369,33 @@ VT::Position TerminalWidget::buffer_position_at(const Point& position) const return { row, column }; } +void TerminalWidget::doubleclick_event(GMouseEvent& event) +{ + if (event.button() == GMouseButton::Left) { + auto position = buffer_position_at(event.position()); + auto& line = m_terminal.line(position.row()); + bool want_whitespace = line.characters[position.column()] == ' '; + + int start_column = 0; + int end_column = 0; + + for (int column = position.column(); column >= 0 && (line.characters[column] == ' ') == want_whitespace; --column) { + start_column = column; + } + + for (int column = position.column(); column < m_terminal.columns() && (line.characters[column] == ' ') == want_whitespace; ++column) { + end_column = column; + } + + m_selection_start = { position.row(), start_column }; + m_selection_end = { position.row(), end_column }; + + if (has_selection()) + GClipboard::the().set_data(selected_text()); + } + GFrame::doubleclick_event(event); +} + void TerminalWidget::mousedown_event(GMouseEvent& event) { if (event.button() == GMouseButton::Left) { diff --git a/Applications/Terminal/TerminalWidget.h b/Applications/Terminal/TerminalWidget.h index e152bffde8..e4c7b0ba26 100644 --- a/Applications/Terminal/TerminalWidget.h +++ b/Applications/Terminal/TerminalWidget.h @@ -51,6 +51,7 @@ private: virtual void mousemove_event(GMouseEvent&) override; virtual void mouseup_event(GMouseEvent&) override; virtual void mousewheel_event(GMouseEvent&) override; + virtual void doubleclick_event(GMouseEvent&) override; // ^TerminalClient virtual void beep() override; |