Commit bd3ca5b4 authored by Ole Christian Eidheim's avatar Ole Christian Eidheim

Simplified Source::View::scroll_to_cursor_delayed

parent 92b09633
Pipeline #94200913 passed with stages
in 16 minutes and 12 seconds
......@@ -86,7 +86,7 @@ void Application::on_activate() {
if(i < file_offsets.size()) {
if(auto view = Notebook::get().get_current_view()) {
view->place_cursor_at_line_offset(file_offsets[i].first, file_offsets[i].second);
view->hide_tooltips();
view->scroll_to_cursor_delayed(true, false);
}
}
}
......@@ -100,15 +100,9 @@ void Application::on_activate() {
auto iter = view->get_buffer()->get_insert()->get_iter();
// To update cursor history
view->place_cursor_at_line_offset(iter.get_line(), iter.get_line_offset());
view->hide_tooltips();
view->scroll_to_cursor_delayed(true, false);
}
}
Glib::signal_idle().connect([] {
for(auto view : Notebook::get().get_views())
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
return false;
});
}
void Application::on_startup() {
......
......@@ -175,11 +175,11 @@ void Notebook::open(const boost::filesystem::path &file_path_, Position position
view->configure();
view->scroll_to_cursor_delayed = [this](Source::BaseView *view, bool center, bool show_tooltips) {
view->scroll_to_cursor_delayed = [this, view](bool center, bool show_tooltips) {
if(!show_tooltips)
view->hide_tooltips();
Glib::signal_idle().connect([this, view, center] {
if(get_current_view() == view) {
if(get_index(view) != static_cast<size_t>(-1)) {
if(center)
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
else
......
......@@ -246,7 +246,7 @@ void Project::Base::show_symbols() {
Notebook::get().open(full_path);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_index(offset.line, offset.index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
};
if(view)
view->hide_tooltips();
......@@ -452,7 +452,7 @@ void Project::LLDB::debug_start() {
Notebook::get().open(stop_path);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_index(stop_line, stop_column);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
else if(auto view = Notebook::get().get_current_view())
view->get_buffer()->place_cursor(view->get_buffer()->get_insert()->get_iter());
......@@ -556,7 +556,7 @@ void Project::LLDB::debug_backtrace() {
Debug::LLDB::get().select_frame(frame.index);
view->place_cursor_at_line_index(frame.line_nr - 1, frame.line_index - 1);
view->scroll_to_cursor_delayed(view, true, true);
view->scroll_to_cursor_delayed(true, true);
}
}
};
......@@ -600,7 +600,7 @@ void Project::LLDB::debug_show_variables() {
Notebook::get().open(variable.file_path);
if(auto view = Notebook::get().get_current_view()) {
view->place_cursor_at_line_index(variable.line_nr - 1, variable.line_index - 1);
view->scroll_to_cursor_delayed(view, true, true);
view->scroll_to_cursor_delayed(true, true);
}
}
if(!variable.declaration_found)
......@@ -792,7 +792,7 @@ void Project::LanguageProtocol::show_symbols() {
Notebook::get().open(offset.file);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_offset(offset.range.start.line, offset.range.start.character);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
};
if(view)
......
......@@ -740,7 +740,7 @@ void Source::BaseView::paste() {
if(only_whitespaces) {
Gtk::Clipboard::get()->set_text(text);
get_buffer()->paste_clipboard(Gtk::Clipboard::get());
scroll_to_cursor_delayed(this, false, false);
scroll_to_cursor_delayed(false, false);
return;
}
......@@ -852,7 +852,7 @@ void Source::BaseView::paste() {
if(text.size() > 0 && text.back() == '\n')
get_buffer()->insert_at_cursor('\n' + prefix_tabs);
get_buffer()->end_user_action();
scroll_to_cursor_delayed(this, false, false);
scroll_to_cursor_delayed(false, false);
}
std::string Source::BaseView::get_selected_text() {
......
......@@ -52,8 +52,7 @@ namespace Source {
/// Safely places cursor at line index
void place_cursor_at_line_index(int line, int index);
/// Use with care, view could be destroyed while this functions is running!
std::function<void(BaseView *view, bool center, bool show_tooltips)> scroll_to_cursor_delayed = [](BaseView *view, bool center, bool show_tooltips) {};
std::function<void(bool center, bool show_tooltips)> scroll_to_cursor_delayed = [](bool center, bool show_tooltips) {};
std::function<void(BaseView *view)> update_tab_label;
std::function<void(BaseView *view)> update_status_location;
......
......@@ -379,7 +379,7 @@ bool Terminal::on_button_press_event(GdkEventButton *button_event) {
int line_int = std::stoi(line) - 1;
int index_int = std::stoi(index) - 1;
view->place_cursor_at_line_index(line_int, index_int);
view->scroll_to_cursor_delayed(view, true, true);
view->scroll_to_cursor_delayed(true, true);
return true;
}
catch(...) {
......
......@@ -136,7 +136,7 @@ void Tooltip::show(bool disregard_drawn, const std::function<void()> &on_motion)
auto line = atoi(sm[2].str().c_str()) - 1;
auto offset = atoi(sm[3].str().c_str()) - 1;
view->place_cursor_at_line_offset(line, offset);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
catch(...) {
}
......
......@@ -685,7 +685,7 @@ void Window::set_menu_actions() {
});
menu.add_action("source_center_cursor", []() {
if(auto view = Notebook::get().get_current_view())
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
});
menu.add_action("source_cursor_history_back", []() {
if(Notebook::get().cursor_locations.size() == 0)
......@@ -711,7 +711,7 @@ void Window::set_menu_actions() {
}
Notebook::get().disable_next_update_cursor_locations = true;
cursor_location->view->get_buffer()->place_cursor(cursor_location->mark->get_iter());
cursor_location->view->scroll_to_cursor_delayed(cursor_location->view, true, false);
cursor_location->view->scroll_to_cursor_delayed(true, false);
});
menu.add_action("source_cursor_history_forward", []() {
if(Notebook::get().cursor_locations.size() <= 1)
......@@ -727,7 +727,7 @@ void Window::set_menu_actions() {
Notebook::get().open(cursor_location.view->file_path);
Notebook::get().disable_next_update_cursor_locations = true;
cursor_location.view->get_buffer()->place_cursor(cursor_location.mark->get_iter());
cursor_location.view->scroll_to_cursor_delayed(cursor_location.view, true, false);
cursor_location.view->scroll_to_cursor_delayed(true, false);
});
menu.add_action("source_show_completion", [] {
......@@ -839,7 +839,7 @@ void Window::set_menu_actions() {
iter = view->get_iter_at_line_pos(offset.line, offset.index);
iter.forward_chars(std::get<2>(documentation_template));
view->get_buffer()->place_cursor(iter);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
}
}
......@@ -895,7 +895,7 @@ void Window::set_menu_actions() {
auto line = static_cast<int>(location.line);
auto index = static_cast<int>(location.index);
view->place_cursor_at_line_pos(line, index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
}
}
......@@ -912,7 +912,7 @@ void Window::set_menu_actions() {
auto line = static_cast<int>(location.line);
auto index = static_cast<int>(location.index);
view->place_cursor_at_line_pos(line, index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
}
}
......@@ -947,7 +947,7 @@ void Window::set_menu_actions() {
auto line = static_cast<int>(location.line);
auto index = static_cast<int>(location.index);
view->place_cursor_at_line_pos(line, index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
return;
}
SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
......@@ -959,7 +959,7 @@ void Window::set_menu_actions() {
Notebook::get().open(location.file_path);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_pos(location.line, location.index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
};
view->hide_tooltips();
SelectionDialog::get()->show();
......@@ -1018,7 +1018,7 @@ void Window::set_menu_actions() {
Notebook::get().open(offset.file_path);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_pos(offset.line, offset.index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
};
view->hide_tooltips();
SelectionDialog::get()->show();
......@@ -1391,7 +1391,7 @@ void Window::set_menu_actions() {
Notebook::get().open(rows[index].file_path);
auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_pos(rows[index].line, rows[index].index);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
};
SelectionDialog::get()->show();
......@@ -1404,7 +1404,7 @@ void Window::set_menu_actions() {
int line = Project::debug_stop.second.first;
int index = Project::debug_stop.second.second;
view->place_cursor_at_line_index(line, index);
view->scroll_to_cursor_delayed(view, true, true);
view->scroll_to_cursor_delayed(true, true);
}
}
}
......@@ -1438,7 +1438,7 @@ void Window::set_menu_actions() {
Notebook::get().open(view->file_path, Notebook::Position::split);
auto new_view = Notebook::get().get_current_view();
new_view->place_cursor_at_line_offset(iter.get_line(), iter.get_line_offset());
new_view->scroll_to_cursor_delayed(new_view, true, false);
new_view->scroll_to_cursor_delayed(true, false);
});
menu.add_action("window_toggle_full_screen", [this] {
if(this->get_window()->get_state() & Gdk::WindowState::WINDOW_STATE_FULLSCREEN)
......@@ -1811,7 +1811,7 @@ void Window::goto_line_entry() {
if(auto view = Notebook::get().get_current_view()) {
try {
view->place_cursor_at_line_index(stoi(content) - 1, 0);
view->scroll_to_cursor_delayed(view, true, false);
view->scroll_to_cursor_delayed(true, false);
}
catch(const std::exception &e) {
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment