From c31cf907ced7d834815454ba507d1257a0b92d16 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 22 Jun 2019 10:38:38 +0200 Subject: [PATCH] GTextEditor: Add select_all() API. Take the implementation of Ctrl+A and expose it as an API for clients. --- LibGUI/GTextEditor.cpp | 17 +++++++++++------ 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 on_change; Function on_return_pressed;