mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00:00
LibGUI: Always show a box when the user requests autocomplete
Previously if there were no suggestions, we simply wouldn't show the autocomplete popup at all. This is functional, but when there are no resultes it does leave the user wondering if it actually worked. Now, if the user requests autocomplete and we do have requests, it behaves exactly as before, but if there' aren't any we now show a box with the message "No suggestions" to show the user that we got the request, there just isn't anything to suggest.
This commit is contained in:
committed by
Andreas Kling
parent
6c776d267a
commit
0627ed9900
@@ -814,7 +814,7 @@ void TextEditor::keydown_event(KeyEvent& event)
|
||||
|
||||
if (is_multi_line() && !event.shift() && !event.alt() && event.ctrl() && event.key() == KeyCode::Key_Space) {
|
||||
if (m_autocomplete_provider) {
|
||||
try_show_autocomplete();
|
||||
try_show_autocomplete(UserRequestedAutocomplete::Yes);
|
||||
update_autocomplete.disarm();
|
||||
return;
|
||||
}
|
||||
@@ -1456,14 +1456,14 @@ void TextEditor::undefer_reflow()
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::try_show_autocomplete()
|
||||
void TextEditor::try_show_autocomplete(UserRequestedAutocomplete user_requested_autocomplete)
|
||||
{
|
||||
if (m_autocomplete_provider) {
|
||||
m_autocomplete_provider->provide_completions([&](auto completions) {
|
||||
auto has_completions = !completions.is_empty();
|
||||
m_autocomplete_box->update_suggestions(move(completions));
|
||||
auto position = content_rect_for_position(cursor()).translated(0, -visible_content_rect().y()).bottom_right().translated(screen_relative_rect().top_left().translated(ruler_width(), 0).translated(10, 5));
|
||||
if (has_completions)
|
||||
if (has_completions || user_requested_autocomplete == Yes)
|
||||
m_autocomplete_box->show(position);
|
||||
});
|
||||
}
|
||||
@@ -1958,7 +1958,7 @@ void TextEditor::set_should_autocomplete_automatically(bool value)
|
||||
|
||||
if (value) {
|
||||
VERIFY(m_autocomplete_provider);
|
||||
m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] { try_show_autocomplete(); });
|
||||
m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] { try_show_autocomplete(UserRequestedAutocomplete::No); });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user