diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-22 10:38:38 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-22 10:38:38 +0200 |
commit | c31cf907ced7d834815454ba507d1257a0b92d16 (patch) | |
tree | d50c567587b8c969b6119c1f2a47ab4e116ad6e6 | |
parent | 9ee63ef8b39ec52bba8293ea8b7d82d37a618a8c (diff) | |
download | serenity-c31cf907ced7d834815454ba507d1257a0b92d16.zip |
GTextEditor: Add select_all() API.
Take the implementation of Ctrl+A and expose it as an API for clients.
-rw-r--r-- | LibGUI/GTextEditor.cpp | 17 | ||||
-rw-r--r-- | LibGUI/GTextEditor.h | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index a21159c36a..660d457236 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -344,6 +344,16 @@ void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event) } } +void GTextEditor::select_all() +{ + GTextPosition start_of_document { 0, 0 }; + GTextPosition end_of_document { line_count() - 1, m_lines[line_count() - 1]->length() }; + m_selection.set(start_of_document, end_of_document); + did_update_selection(); + set_cursor(end_of_document); + update(); +} + void GTextEditor::keydown_event(GKeyEvent& event) { if (is_single_line() && event.key() == KeyCode::Key_Tab) @@ -485,12 +495,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) return; } if (event.modifiers() == Mod_Ctrl && event.key() == KeyCode::Key_A) { - GTextPosition start_of_document { 0, 0 }; - GTextPosition end_of_document { line_count() - 1, m_lines[line_count() - 1]->length() }; - m_selection.set(start_of_document, end_of_document); - did_update_selection(); - set_cursor(end_of_document); - update(); + select_all(); return; } diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h index fc7b387cac..1bfbfa5b70 100644 --- a/LibGUI/GTextEditor.h +++ b/LibGUI/GTextEditor.h @@ -127,6 +127,7 @@ public: void paste(); void do_delete(); void delete_current_line(); + void select_all(); Function<void()> on_change; Function<void()> on_return_pressed; |