diff --git a/juci/notebook.cc b/juci/notebook.cc index e812dcd..51093dc 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -81,7 +81,7 @@ void Notebook::Controller::CreateKeybindings() { if(location.first.size()>0) { open_file(location.first); CurrentSourceView()->get_buffer()->place_cursor(CurrentSourceView()->get_buffer()->get_iter_at_offset(location.second)); - CurrentSourceView()->scroll_to_insert(); + CurrentSourceView()->scroll_to(CurrentSourceView()->get_buffer()->get_insert()); } } } diff --git a/juci/source.cc b/juci/source.cc index 6643431..86c72fb 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -47,7 +47,8 @@ file_path(file_path), project_path(project_path) { get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; } - scroll_to_insert_dispatcher.connect([this](){ + get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); + signal_size_allocate().connect([this](Gtk::Allocation& allocation){ scroll_to(get_buffer()->get_insert()); }); } @@ -68,15 +69,6 @@ string Source::View::get_line_before_insert() { return line; } -//TODO: Fix this dirty hack. Gtk's scroll_to is bugged... -void Source::View::scroll_to_insert() { - std::thread scroll_to_insert_thread([this](){ - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - scroll_to_insert_dispatcher(); - }); - scroll_to_insert_thread.detach(); -} - //Basic indentation bool Source::View::on_key_press_event(GdkEventKey* key) { auto config=Singleton::Config::source(); diff --git a/juci/source.h b/juci/source.h index 26dc02f..14cc2a6 100644 --- a/juci/source.h +++ b/juci/source.h @@ -49,7 +49,6 @@ public: View(const std::string& file_path, const std::string& project_path); std::string get_line(size_t line_number); std::string get_line_before_insert(); - void scroll_to_insert(); std::string file_path; std::string project_path; Gtk::TextIter search_start, search_end; @@ -57,8 +56,6 @@ public: std::function()> get_declaration_location; protected: bool on_key_press_event(GdkEventKey* key); - private: - Glib::Dispatcher scroll_to_insert_dispatcher; }; // class View class GenericView : public View { diff --git a/juci/terminal.cc b/juci/terminal.cc index aad7e45..781a052 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -51,6 +51,10 @@ Terminal::View::View(){ Terminal::Controller::Controller() { folder_command_ = ""; + view.text_view.signal_size_allocate().connect([this](Gtk::Allocation& allocation){ + auto iter=view.text_view.get_buffer()->end(); + view.text_view.scroll_to(iter); + }); } void Terminal::Controller::SetFolderCommand( boost::filesystem::path @@ -86,11 +90,7 @@ void Terminal::Controller::Run(std::string executable) { int Terminal::Controller::print(std::string message){ INFO("Terminal: PrintMessage"); view.text_view.get_buffer()->insert(view.text_view.get_buffer()->end(), "> "+message); - auto mark_end=view.text_view.get_buffer()->create_mark(view.text_view.get_buffer()->end()); - view.text_view.scroll_to(view.text_view.get_buffer()->get_insert()); - auto line=mark_end->get_iter().get_line(); - view.text_view.get_buffer()->delete_mark(mark_end); - return line; + return view.text_view.get_buffer()->end().get_line(); } void Terminal::Controller::print(int line_nr, std::string message){