diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index d9f393c250..afa7ad20cb 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -106,14 +106,12 @@ Locator::Locator(GWidget* parent) m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical); } }; + m_textbox->on_return_pressed = [this] { auto selected_index = m_suggestion_view->selection().first(); if (!selected_index.is_valid()) return; - auto filename_index = m_suggestion_view->model()->index(selected_index.row(), LocatorSuggestionModel::Column::Name); - auto filename = m_suggestion_view->model()->data(filename_index, GModel::Role::Display).to_string(); - open_file(filename); - close(); + open_suggestion(selected_index); }; m_popup_window = GWindow::construct(); @@ -125,12 +123,25 @@ Locator::Locator(GWidget* parent) m_suggestion_view->set_size_columns_to_fit_content(true); m_suggestion_view->set_headers_visible(false); m_popup_window->set_main_widget(m_suggestion_view); + + + m_suggestion_view->on_activation = [this](auto& index) { + open_suggestion(index); + }; } Locator::~Locator() { } +void Locator::open_suggestion(const GModelIndex& index) +{ + auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); + auto filename = m_suggestion_view->model()->data(filename_index, GModel::Role::Display).to_string(); + open_file(filename); + close(); +} + void Locator::open() { m_textbox->set_focus(true); diff --git a/DevTools/HackStudio/Locator.h b/DevTools/HackStudio/Locator.h index 2e6269b503..38759a0773 100644 --- a/DevTools/HackStudio/Locator.h +++ b/DevTools/HackStudio/Locator.h @@ -3,6 +3,7 @@ #include class LocatorTextBox; +class GModelIndex; class GTableView; class Locator final : public GWidget { @@ -17,6 +18,7 @@ private: virtual void keydown_event(GKeyEvent&) override; void update_suggestions(); + void open_suggestion(const GModelIndex&); explicit Locator(GWidget* parent);