From d217d3ff6fddf1b8dec4345a8d233725201e14af Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Feb 2020 20:58:25 +0100 Subject: [PATCH] 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. --- DevTools/HackStudio/Locator.cpp | 11 +++++++++-- 1 file 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();