1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 21:25:07 +00:00

TextEditor: Search box should find on return, close itself on escape

This patch adds basic keyboard access to the search box. We also yield
focus back gracefully to the text document when the search box is no
longer wanted.

Focus should probably move automatically when an ancestor of the
currently focused widget if made invisible..
This commit is contained in:
Andreas Kling 2019-08-22 11:09:25 +02:00
parent 96c5c9ce12
commit fae379b1f0
2 changed files with 21 additions and 11 deletions

View file

@ -24,17 +24,17 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_ruler_visible(true);
m_editor->set_automatic_indentation_enabled(true);
auto* find_widget = new GWidget(this);
find_widget->set_fill_with_background_color(true);
find_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
find_widget->set_preferred_size(0, 22);
find_widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
find_widget->layout()->set_margins({ 2, 2, 2, 2 });
find_widget->set_visible(false);
m_find_widget = new GWidget(this);
m_find_widget->set_fill_with_background_color(true);
m_find_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_find_widget->set_preferred_size(0, 22);
m_find_widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
m_find_widget->layout()->set_margins({ 2, 2, 2, 2 });
m_find_widget->set_visible(false);
m_find_textbox = new GTextBox(find_widget);
m_find_textbox = new GTextBox(m_find_widget);
m_find_button = new GButton("Find", find_widget);
m_find_button = new GButton("Find", m_find_widget);
m_find_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_find_button->set_preferred_size(100, 0);
@ -53,8 +53,17 @@ TextEditorWidget::TextEditorWidget()
}
};
m_find_action = GAction::create("Find...", { Mod_Ctrl, Key_F }, [this, find_widget](auto&) {
find_widget->set_visible(true);
m_find_textbox->on_return_pressed = [this] {
m_find_button->click();
};
m_find_textbox->on_escape_pressed = [this] {
m_find_widget->set_visible(false);
m_editor->set_focus(true);
};
m_find_action = GAction::create("Find...", { Mod_Ctrl, Key_F }, [this](auto&) {
m_find_widget->set_visible(true);
m_find_textbox->set_focus(true);
});