mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
PixelPaint: Enable more text tool keyboard shortcuts
This commit allows the text tool's internal TextEditor component to handle keyboard shortcuts that would normally be handled by menu actions. The shortcuts that can now be used are: cut, copy, paste, undo, redo and select all.
This commit is contained in:
parent
c63f70d0fd
commit
3d9ba87077
2 changed files with 16 additions and 0 deletions
|
@ -30,6 +30,12 @@ void TextToolEditor::handle_keyevent(Badge<TextTool>, GUI::KeyEvent& event)
|
|||
TextEditor::keydown_event(event);
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<GUI::Action> TextToolEditor::actions()
|
||||
{
|
||||
static NonnullRefPtrVector<GUI::Action> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue