diff --git a/src/window.cc b/src/window.cc index 345cca2..476d6e6 100644 --- a/src/window.cc +++ b/src/window.cc @@ -363,11 +363,23 @@ void Window::create_menu() { auto location=notebook.get_current_view()->get_declaration_location(); if(location.first.size()>0) { notebook.open(location.first); - notebook.get_current_view()->get_buffer()->place_cursor(notebook.get_current_view()->get_buffer()->get_iter_at_line_index(location.second.line-1, location.second.index-1)); - while(gtk_events_pending()) - gtk_main_iteration(); - if(notebook.get_current_page()!=-1) - notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + auto line=static_cast(location.second.line)-1; + auto index=static_cast(location.second.index)-1; + auto buffer=notebook.get_current_view()->get_buffer(); + line=std::min(line, buffer->get_line_count()-1); + if(line>=0) { + auto iter=buffer->get_iter_at_line(line); + while(!iter.ends_line()) + iter.forward_char(); + auto end_line_index=iter.get_line_index(); + index=std::min(index, end_line_index); + buffer->place_cursor(buffer->get_iter_at_line_index(line, index)); + + while(gtk_events_pending()) + gtk_main_iteration(); + if(notebook.get_current_page()!=-1) + notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + } } } }