diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-07 20:58:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-07 20:58:44 +0100 |
commit | d217d3ff6fddf1b8dec4345a8d233725201e14af (patch) | |
tree | c67c2fe768f13dc085dba811aacb822b0e62c234 /DevTools/HackStudio | |
parent | 3d62cab90fa5cafd918c548017acc839af21c4d3 (diff) | |
download | serenity-d217d3ff6fddf1b8dec4345a8d233725201e14af.zip |
HackStudio: Disallow invalid indices when typing into the locator
The locator was a bit crashy since it would allow you to navigate
to invalid indices.
Diffstat (limited to 'DevTools/HackStudio')
-rw-r--r-- | DevTools/HackStudio/Locator.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index 31dfd8855e..609cc57b66 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -124,7 +124,7 @@ Locator::Locator(GUI::Widget* parent) else new_index = m_suggestion_view->model()->index(0); - if (new_index.is_valid()) { + if (m_suggestion_view->model()->is_valid(new_index)) { m_suggestion_view->selection().set(new_index); m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical); } @@ -136,7 +136,7 @@ Locator::Locator(GUI::Widget* parent) else new_index = m_suggestion_view->model()->index(0); - if (new_index.is_valid()) { + if (m_suggestion_view->model()->is_valid(new_index)) { m_suggestion_view->selection().set(new_index); m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical); } @@ -203,8 +203,15 @@ void Locator::update_suggestions() dbg() << " " << s; } + bool has_suggestions = !suggestions.is_empty(); + m_suggestion_view->set_model(adopt(*new LocatorSuggestionModel(move(suggestions)))); + if (!has_suggestions) + m_suggestion_view->selection().clear(); + else + m_suggestion_view->selection().set(m_suggestion_view->model()->index(0)); + m_popup_window->move_to(screen_relative_rect().top_left().translated(0, -m_popup_window->height())); dbg() << "Popup rect: " << m_popup_window->rect(); m_popup_window->show(); |