diff --git a/src/selectiondialog.cc b/src/selectiondialog.cc index ec836cf..2116057 100644 --- a/src/selectiondialog.cc +++ b/src/selectiondialog.cc @@ -115,7 +115,22 @@ void SelectionDialogBase::show() { window->show_all(); if(list_view_text.get_model()->children().size()>0) { - list_view_text.set_cursor(list_view_text.get_model()->get_path(list_view_text.get_model()->children().begin())); + if(!list_view_text.get_selection()->get_selected()) { + list_view_text.set_cursor(list_view_text.get_model()->get_path(list_view_text.get_model()->children().begin())); + cursor_changed(); + } + else if(list_view_text.get_model()->children().begin()!=list_view_text.get_selection()->get_selected()) { + while(g_main_context_pending(NULL)) + g_main_context_iteration(NULL, false); + list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5); + } + } +} + +void SelectionDialogBase::set_cursor_at_last_row() { + auto children=list_view_text.get_model()->children(); + if(children.size()>0) { + list_view_text.set_cursor(list_view_text.get_model()->get_path(children[children.size()-1])); cursor_changed(); } } diff --git a/src/selectiondialog.h b/src/selectiondialog.h index bff6c73..fa49c12 100644 --- a/src/selectiondialog.h +++ b/src/selectiondialog.h @@ -28,6 +28,7 @@ public: SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup); ~SelectionDialogBase(); void add_row(const std::string& row); + void set_cursor_at_last_row(); void show(); void hide(); void move(); diff --git a/src/window.cc b/src/window.cc index 6dbd6a6..da0e61a 100644 --- a/src/window.cc +++ b/src/window.cc @@ -488,18 +488,28 @@ void Window::set_menu_actions() { if(view->get_usages) { auto usages=view->get_usages(Notebook::get().get_views()); if(!usages.empty()) { - auto iter=view->get_iter_for_dialog(); - view->selection_dialog=std::unique_ptr(new SelectionDialog(*view, view->get_buffer()->create_mark(iter), true, true)); + auto dialog_iter=view->get_iter_for_dialog(); + view->selection_dialog=std::unique_ptr(new SelectionDialog(*view, view->get_buffer()->create_mark(dialog_iter), true, true)); auto rows=std::make_shared >(); + auto iter=view->get_buffer()->get_insert()->get_iter(); for(auto &usage: usages) { std::string row; - //add file name if usage is not in current tab - if(view->file_path!=usage.first.file_path) + bool current_page=true; + //add file name if usage is not in current page + if(view->file_path!=usage.first.file_path) { row=usage.first.file_path.filename().string()+":"; + current_page=false; + } row+=std::to_string(usage.first.line+1)+": "+usage.second; (*rows)[row]=usage.first; view->selection_dialog->add_row(row); + + //Set dialog cursor to the last row if the textview cursor is at the same line + if(current_page) { + if(iter.get_line()==static_cast(usage.first.line) && iter.get_line_index()>=static_cast(usage.first.index)) + view->selection_dialog->set_cursor_at_last_row(); + } } if(rows->size()==0)