mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 14:55:07 +00:00
GTextEditor: Create the "go to line" action eagerly
Previously it was created the first time you requested a context menu for the GTextEditor by right-clicking in it. That meant it wasn't possible to use Ctrl+L to "go to line" before you had first right-clicked the editor.
This commit is contained in:
parent
a33259483a
commit
1c34348b0c
2 changed files with 15 additions and 11 deletions
|
@ -83,6 +83,18 @@ void GTextEditor::create_actions()
|
|||
m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this);
|
||||
m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
||||
m_delete_action = GCommonActions::make_delete_action([&](auto&) { do_delete(); }, this);
|
||||
m_go_to_line_action = GAction::create(
|
||||
"Go to line...", { Mod_Ctrl, Key_L }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
||||
auto input_box = GInputBox::construct("Line:", "Go to line", window());
|
||||
auto result = input_box->exec();
|
||||
if (result == GInputBox::ExecOK) {
|
||||
bool ok;
|
||||
auto line_number = input_box->text_value().to_uint(ok);
|
||||
if (ok)
|
||||
set_cursor(line_number - 1, 0);
|
||||
}
|
||||
},
|
||||
this);
|
||||
}
|
||||
|
||||
void GTextEditor::set_text(const StringView& text)
|
||||
|
@ -1223,17 +1235,7 @@ void GTextEditor::context_menu_event(GContextMenuEvent& event)
|
|||
m_context_menu->add_action(delete_action());
|
||||
if (is_multi_line()) {
|
||||
m_context_menu->add_separator();
|
||||
m_context_menu->add_action(GAction::create(
|
||||
"Go to line...", { Mod_Ctrl, Key_L }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
||||
auto input_box = GInputBox::construct("Line:", "Go to line", window());
|
||||
auto result = input_box->exec();
|
||||
if (result == GInputBox::ExecOK) {
|
||||
bool ok;
|
||||
auto line_number = input_box->text_value().to_uint(ok);
|
||||
if (ok)
|
||||
set_cursor(line_number - 1, 0);
|
||||
}
|
||||
}));
|
||||
m_context_menu->add_action(go_to_line_action());
|
||||
}
|
||||
if (!m_custom_context_menu_actions.is_empty()) {
|
||||
m_context_menu->add_separator();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue