mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibGUI: Hide autocomplete on any event other than typing
Moving the cursor to a different location, by any means, should dismiss the autocomplete popup. This is the behavior of virtually every editor/IDE out there, and it is really annoying (and confusing) when our autocomplete doesn't behave like that.
This commit is contained in:
parent
0627ed9900
commit
86ea41970d
2 changed files with 18 additions and 7 deletions
|
@ -738,7 +738,6 @@ void TextEditor::select_all()
|
||||||
|
|
||||||
void TextEditor::keydown_event(KeyEvent& event)
|
void TextEditor::keydown_event(KeyEvent& event)
|
||||||
{
|
{
|
||||||
TemporaryChange change { m_should_keep_autocomplete_box, true };
|
|
||||||
if (m_autocomplete_box && m_autocomplete_box->is_visible() && (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Tab)) {
|
if (m_autocomplete_box && m_autocomplete_box->is_visible() && (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Tab)) {
|
||||||
m_autocomplete_box->apply_suggestion();
|
m_autocomplete_box->apply_suggestion();
|
||||||
m_autocomplete_box->close();
|
m_autocomplete_box->close();
|
||||||
|
@ -882,6 +881,7 @@ void TextEditor::keydown_event(KeyEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.ctrl() && !event.alt() && event.code_point() != 0) {
|
if (!event.ctrl() && !event.alt() && event.code_point() != 0) {
|
||||||
|
TemporaryChange change { m_should_keep_autocomplete_box, true };
|
||||||
add_code_point(event.code_point());
|
add_code_point(event.code_point());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1469,6 +1469,15 @@ void TextEditor::try_show_autocomplete(UserRequestedAutocomplete user_requested_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditor::hide_autocomplete_if_needed()
|
||||||
|
{
|
||||||
|
if (m_autocomplete_box && !m_should_keep_autocomplete_box) {
|
||||||
|
m_autocomplete_box->close();
|
||||||
|
if (m_autocomplete_timer)
|
||||||
|
m_autocomplete_timer->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditor::enter_event(Core::Event&)
|
void TextEditor::enter_event(Core::Event&)
|
||||||
{
|
{
|
||||||
m_automatic_selection_scroll_timer->stop();
|
m_automatic_selection_scroll_timer->stop();
|
||||||
|
@ -1484,11 +1493,7 @@ void TextEditor::did_change(AllowCallback allow_callback)
|
||||||
{
|
{
|
||||||
update_content_size();
|
update_content_size();
|
||||||
recompute_all_visual_lines();
|
recompute_all_visual_lines();
|
||||||
if (m_autocomplete_box && !m_should_keep_autocomplete_box) {
|
hide_autocomplete_if_needed();
|
||||||
m_autocomplete_box->close();
|
|
||||||
if (m_autocomplete_timer)
|
|
||||||
m_autocomplete_timer->stop();
|
|
||||||
}
|
|
||||||
m_needs_rehighlight = true;
|
m_needs_rehighlight = true;
|
||||||
if (!m_has_pending_change_notification) {
|
if (!m_has_pending_change_notification) {
|
||||||
m_has_pending_change_notification = true;
|
m_has_pending_change_notification = true;
|
||||||
|
@ -1827,6 +1832,11 @@ void TextEditor::document_did_set_cursor(TextPosition const& position)
|
||||||
set_cursor(position);
|
set_cursor(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditor::cursor_did_change()
|
||||||
|
{
|
||||||
|
hide_autocomplete_if_needed();
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditor::clipboard_content_did_change(String const& mime_type)
|
void TextEditor::clipboard_content_did_change(String const& mime_type)
|
||||||
{
|
{
|
||||||
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());
|
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||||
|
|
|
@ -229,7 +229,7 @@ protected:
|
||||||
virtual void context_menu_event(ContextMenuEvent&) override;
|
virtual void context_menu_event(ContextMenuEvent&) override;
|
||||||
virtual void resize_event(ResizeEvent&) override;
|
virtual void resize_event(ResizeEvent&) override;
|
||||||
virtual void theme_change_event(ThemeChangeEvent&) override;
|
virtual void theme_change_event(ThemeChangeEvent&) override;
|
||||||
virtual void cursor_did_change() { }
|
virtual void cursor_did_change();
|
||||||
Gfx::IntRect ruler_content_rect(size_t line) const;
|
Gfx::IntRect ruler_content_rect(size_t line) const;
|
||||||
Gfx::IntRect gutter_content_rect(size_t line) const;
|
Gfx::IntRect gutter_content_rect(size_t line) const;
|
||||||
|
|
||||||
|
@ -279,6 +279,7 @@ private:
|
||||||
Yes
|
Yes
|
||||||
};
|
};
|
||||||
void try_show_autocomplete(UserRequestedAutocomplete);
|
void try_show_autocomplete(UserRequestedAutocomplete);
|
||||||
|
void hide_autocomplete_if_needed();
|
||||||
|
|
||||||
int icon_size() const { return 16; }
|
int icon_size() const { return 16; }
|
||||||
int icon_padding() const { return 2; }
|
int icon_padding() const { return 2; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue