From 5901d2e06b7c43fd0e6156a49761b81b747ea908 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 17 Jun 2023 17:30:43 +1000 Subject: Revert "Switch undo storage from a tree to a plain list" Moving across history moved to / to keep / for selection undo/redo This reverts commit e0d33f51b36c9f0be7ae2467dab455d211bbf561. --- src/normal.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 68392199..08ce028d 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -2010,6 +2010,29 @@ void redo(Context& context, NormalParams params) throw runtime_error("nothing left to redo"); } +template +void move_in_history(Context& context, NormalParams params) +{ + Buffer& buffer = context.buffer(); + size_t timestamp = buffer.timestamp(); + const int count = std::max(1, params.count); + const int history_id = (size_t)buffer.current_history_id() + direction * count; + const int max_history_id = (int)buffer.next_history_id() - 1; + if (buffer.move_to((Buffer::HistoryId)history_id)) + { + auto ranges = compute_modified_ranges(buffer, timestamp); + if (not ranges.empty()) + context.selections_write_only() = std::move(ranges); + + context.print_status({ format("moved to change #{} ({})", + history_id, max_history_id), + context.faces()["Information"] }); + } + else + throw runtime_error(format("no such change: #{} ({})", + history_id, max_history_id)); +} + template void undo_selection_change(Context& context, NormalParams params) { @@ -2339,6 +2362,8 @@ static constexpr HashMap { {'u'}, {"undo", undo} }, { {'U'}, {"redo", redo} }, + { {ctrl('k')}, {"move backward in history", move_in_history} }, + { {ctrl('j')}, {"move forward in history", move_in_history} }, { {alt('u')}, {"undo selection change", undo_selection_change} }, { {alt('U')}, {"redo selection change", undo_selection_change} }, -- cgit v1.2.3