mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
Terminal: Allow selecting words by double-clicking them
Bonus feature: also allow selecting the whitespace in-between words by double-clicking that. :^)
This commit is contained in:
parent
fae379b1f0
commit
1ca6adee90
2 changed files with 28 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue