|
|
|
|
@ -327,27 +327,62 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Cursor history
|
|
|
|
|
auto update_cursor_locations = [this, view]() { |
|
|
|
|
auto iter = view->get_buffer()->get_insert()->get_iter(); |
|
|
|
|
auto add_cursor_location = [this, view](const Gtk::TextIter &iter) { |
|
|
|
|
if(current_cursor_location != cursor_locations.end()) { |
|
|
|
|
// Remove history newer than current (create new history branch)
|
|
|
|
|
for(auto it = std::next(current_cursor_location); it != cursor_locations.end();) { |
|
|
|
|
it->view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
it = cursor_locations.erase(it); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
current_cursor_location = cursor_locations.emplace(cursor_locations.end(), view, view->get_buffer()->create_mark(iter, false)); |
|
|
|
|
if(cursor_locations.size() > 10) { |
|
|
|
|
auto it = cursor_locations.begin(); |
|
|
|
|
it->view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
cursor_locations.erase(it); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
view->get_buffer()->signal_mark_set().connect([this, view, add_cursor_location](const Gtk::TextBuffer::iterator & /*iter*/, const Glib::RefPtr<Gtk::TextBuffer::Mark> &mark) { |
|
|
|
|
if(mark->get_name() == "insert") { |
|
|
|
|
if(disable_next_update_cursor_locations) { |
|
|
|
|
disable_next_update_cursor_locations = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool moved = false; |
|
|
|
|
auto iter = mark->get_iter(); |
|
|
|
|
if(current_cursor_location != cursor_locations.end()) { |
|
|
|
|
if(current_cursor_location->view == view && abs(current_cursor_location->mark->get_iter().get_line() - iter.get_line()) <= 2) { |
|
|
|
|
current_cursor_location->view->get_buffer()->move_mark(current_cursor_location->mark, iter); // Move current cursor
|
|
|
|
|
moved = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!moved) { |
|
|
|
|
// Remove history newer than current (create new history branch)
|
|
|
|
|
for(auto it = std::next(current_cursor_location); it != cursor_locations.end();) { |
|
|
|
|
// Combine cursor histories adjacent and similar to current cursor
|
|
|
|
|
auto it = std::next(current_cursor_location); |
|
|
|
|
if(it != cursor_locations.end()) { |
|
|
|
|
if(it->view == current_cursor_location->view && abs(it->mark->get_iter().get_line() - current_cursor_location->mark->get_iter().get_line()) <= 2) { |
|
|
|
|
it->view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
it = cursor_locations.erase(it); |
|
|
|
|
cursor_locations.erase(it); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(current_cursor_location != cursor_locations.begin()) { |
|
|
|
|
it = std::prev(current_cursor_location); |
|
|
|
|
if(it->view == current_cursor_location->view && abs(it->mark->get_iter().get_line() - current_cursor_location->mark->get_iter().get_line()) <= 2) { |
|
|
|
|
it->view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
cursor_locations.erase(it); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!moved) |
|
|
|
|
current_cursor_location = cursor_locations.emplace(cursor_locations.end(), view, view->get_buffer()->create_mark(iter, false)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
add_cursor_location(iter); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
view->get_buffer()->signal_insert().connect([this, view, add_cursor_location](const Gtk::TextBuffer::iterator & /*iter*/, const Glib::ustring & /*text*/, int /*bytes*/) { |
|
|
|
|
if(current_cursor_location == cursor_locations.end() || current_cursor_location->view != view) |
|
|
|
|
add_cursor_location(view->get_buffer()->get_insert()->get_iter()); |
|
|
|
|
}); |
|
|
|
|
view->get_buffer()->signal_erase().connect([this, view, add_cursor_location](const Gtk::TextBuffer::iterator & /*start*/, const Gtk::TextBuffer::iterator & /*end*/) { |
|
|
|
|
if(current_cursor_location == cursor_locations.end() || current_cursor_location->view != view) |
|
|
|
|
add_cursor_location(view->get_buffer()->get_insert()->get_iter()); |
|
|
|
|
|
|
|
|
|
// Combine adjacent cursor histories that are similar
|
|
|
|
|
if(cursor_locations.size() > 1) { |
|
|
|
|
@ -371,26 +406,6 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!moved) { |
|
|
|
|
if(cursor_locations.size() > 10) { |
|
|
|
|
auto it = cursor_locations.begin(); |
|
|
|
|
it->view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
cursor_locations.erase(it); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
view->get_buffer()->signal_mark_set().connect([this, update_cursor_locations](const Gtk::TextBuffer::iterator & /*iter*/, const Glib::RefPtr<Gtk::TextBuffer::Mark> &mark) { |
|
|
|
|
if(mark->get_name() == "insert") { |
|
|
|
|
if(disable_next_update_cursor_locations) { |
|
|
|
|
disable_next_update_cursor_locations = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
update_cursor_locations(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
view->get_buffer()->signal_changed().connect([update_cursor_locations] { |
|
|
|
|
update_cursor_locations(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
#ifdef JUCI_ENABLE_DEBUG |
|
|
|
|
|