diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-25 22:29:25 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-25 22:29:25 +0200 |
commit | e2e2c783326eca1583c2a42cbd02ecb2ec630daa (patch) | |
tree | 59a97f326c214b015266358383b34b814be322fa /LibGUI | |
parent | 44673c4f3b092f03ed8607b743903cf03d46b3f2 (diff) | |
download | serenity-e2e2c783326eca1583c2a42cbd02ecb2ec630daa.zip |
GTextEditor: Double-clicking on a word should select that word.
Diffstat (limited to 'LibGUI')
-rw-r--r-- | LibGUI/GTextEditor.cpp | 29 | ||||
-rw-r--r-- | LibGUI/GTextEditor.h | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index ee2683750f..c8e169ab6a 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -11,6 +11,7 @@ #include <unistd.h> #include <fcntl.h> #include <stdio.h> +#include <ctype.h> GTextEditor::GTextEditor(Type type, GWidget* parent) : GScrollableWidget(parent) @@ -129,6 +130,34 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const return { line_index, column_index }; } +void GTextEditor::doubleclick_event(GMouseEvent& event) +{ + if (event.button() != GMouseButton::Left) + return; + + m_in_drag_select = false; + + auto start = text_position_at(event.position()); + auto end = start; + auto& line = *m_lines[start.line()]; + while (start.column() > 0) { + if (isspace(line.characters()[start.column() - 1])) + break; + start.set_column(start.column() - 1); + } + + while (end.column() < line.length()) { + if (isspace(line.characters()[end.column()])) + break; + end.set_column(end.column() + 1); + } + + m_selection.set(start, end); + set_cursor(end); + update(); + did_update_selection(); +} + void GTextEditor::mousedown_event(GMouseEvent& event) { if (event.button() == GMouseButton::Left) { diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h index 9b31274cb9..0b3a78fbdd 100644 --- a/LibGUI/GTextEditor.h +++ b/LibGUI/GTextEditor.h @@ -125,6 +125,7 @@ private: virtual void mousedown_event(GMouseEvent&) override; virtual void mouseup_event(GMouseEvent&) override; virtual void mousemove_event(GMouseEvent&) override; + virtual void doubleclick_event(GMouseEvent&) override; virtual void keydown_event(GKeyEvent&) override; virtual void focusin_event(CEvent&) override; virtual void focusout_event(CEvent&) override; |