diff --git a/Userland/Applications/PixelPaint/Tools/TextTool.cpp b/Userland/Applications/PixelPaint/Tools/TextTool.cpp index df62724f45..4bad020fb4 100644 --- a/Userland/Applications/PixelPaint/Tools/TextTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/TextTool.cpp @@ -30,6 +30,12 @@ void TextToolEditor::handle_keyevent(Badge, GUI::KeyEvent& event) TextEditor::keydown_event(event); } +NonnullRefPtrVector TextToolEditor::actions() +{ + static NonnullRefPtrVector actions = { cut_action(), copy_action(), paste_action(), undo_action(), redo_action(), select_all_action() }; + return actions; +} + TextTool::TextTool() { m_text_editor = TextToolEditor::construct(); @@ -282,6 +288,15 @@ bool TextTool::on_keydown(GUI::KeyEvent& event) return true; } + // Pass key events that would normally be handled by menu shortcuts to our TextEditor subclass. + for (auto& action : m_text_editor->actions()) { + auto const& shortcut = action.shortcut(); + if (event.key() == shortcut.key() && event.modifiers() == shortcut.modifiers()) { + action.activate(m_text_editor); + return true; + } + } + // Pass the key event off to our TextEditor subclass which handles all text entry features like // caret navigation, backspace/delete, etc. m_text_editor->handle_keyevent({}, event); diff --git a/Userland/Applications/PixelPaint/Tools/TextTool.h b/Userland/Applications/PixelPaint/Tools/TextTool.h index 9f80be38b8..1396290d30 100644 --- a/Userland/Applications/PixelPaint/Tools/TextTool.h +++ b/Userland/Applications/PixelPaint/Tools/TextTool.h @@ -22,6 +22,7 @@ class TextToolEditor : public GUI::TextEditor { public: virtual ~TextToolEditor() override = default; virtual void handle_keyevent(Badge, GUI::KeyEvent&); + NonnullRefPtrVector actions(); protected: TextToolEditor();