mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 08:56:40 +00:00
LibGUI: Add Select all action to TextEditor
Previously, TextEditor processed the Select all command directly on the keydown event handler. For this reason, WindowManager would not process it as an action for the focused control and an action with the same keyboard shortcut from the parent could override the TextEditor's one even when it is focused. For instance, when pressing Ctrl+A on the FileManager's path bar, all files were selected instead, which is not the expected behavior. Now the Select all command is an actual action on TextEditor, so that WindowManager can process it correctly before any other actions. I also added an icon for it!
This commit is contained in:
parent
563a377f6b
commit
441c2715bb
BIN
Base/res/icons/16x16/select-all.png
Normal file
BIN
Base/res/icons/16x16/select-all.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -98,6 +98,8 @@ void TextEditor::create_actions()
|
|||
},
|
||||
this);
|
||||
}
|
||||
m_select_all_action = Action::create(
|
||||
"Select all", { Mod_Ctrl, Key_A },Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), [this](auto&) { select_all(); }, this);
|
||||
}
|
||||
|
||||
void TextEditor::set_text(const StringView& text)
|
||||
|
@ -812,10 +814,6 @@ void TextEditor::keydown_event(KeyEvent& event)
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (event.modifiers() == Mod_Ctrl && event.key() == KeyCode::Key_A) {
|
||||
select_all();
|
||||
return;
|
||||
}
|
||||
if (event.alt() && event.shift() && event.key() == KeyCode::Key_S) {
|
||||
sort_selected_lines();
|
||||
return;
|
||||
|
@ -1277,6 +1275,8 @@ void TextEditor::context_menu_event(ContextMenuEvent& event)
|
|||
m_context_menu->add_action(copy_action());
|
||||
m_context_menu->add_action(paste_action());
|
||||
m_context_menu->add_action(delete_action());
|
||||
m_context_menu->add_separator();
|
||||
m_context_menu->add_action(select_all_action());
|
||||
if (is_multi_line()) {
|
||||
m_context_menu->add_separator();
|
||||
m_context_menu->add_action(go_to_line_action());
|
||||
|
|
|
@ -121,6 +121,7 @@ public:
|
|||
Action& paste_action() { return *m_paste_action; }
|
||||
Action& delete_action() { return *m_delete_action; }
|
||||
Action& go_to_line_action() { return *m_go_to_line_action; }
|
||||
Action& select_all_action() { return *m_select_all_action; }
|
||||
|
||||
void add_custom_context_menu_action(Action&);
|
||||
|
||||
|
@ -233,6 +234,7 @@ private:
|
|||
RefPtr<Action> m_paste_action;
|
||||
RefPtr<Action> m_delete_action;
|
||||
RefPtr<Action> m_go_to_line_action;
|
||||
RefPtr<Action> m_select_all_action;
|
||||
Core::ElapsedTimer m_triple_click_timer;
|
||||
NonnullRefPtrVector<Action> m_custom_context_menu_actions;
|
||||
|
||||
|
|
Loading…
Reference in a new issue