mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
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.
This commit is contained in:
parent
3d62cab90f
commit
d217d3ff6f
1 changed files with 9 additions and 2 deletions
|
@ -124,7 +124,7 @@ Locator::Locator(GUI::Widget* parent)
|
||||||
else
|
else
|
||||||
new_index = m_suggestion_view->model()->index(0);
|
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->selection().set(new_index);
|
||||||
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
|
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ Locator::Locator(GUI::Widget* parent)
|
||||||
else
|
else
|
||||||
new_index = m_suggestion_view->model()->index(0);
|
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->selection().set(new_index);
|
||||||
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
|
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
|
||||||
}
|
}
|
||||||
|
@ -203,8 +203,15 @@ void Locator::update_suggestions()
|
||||||
dbg() << " " << s;
|
dbg() << " " << s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_suggestions = !suggestions.is_empty();
|
||||||
|
|
||||||
m_suggestion_view->set_model(adopt(*new LocatorSuggestionModel(move(suggestions))));
|
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()));
|
m_popup_window->move_to(screen_relative_rect().top_left().translated(0, -m_popup_window->height()));
|
||||||
dbg() << "Popup rect: " << m_popup_window->rect();
|
dbg() << "Popup rect: " << m_popup_window->rect();
|
||||||
m_popup_window->show();
|
m_popup_window->show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue