summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-06-17 17:30:43 +1000
committerMaxime Coste <mawww@kakoune.org>2023-06-17 17:31:57 +1000
commit5901d2e06b7c43fd0e6156a49761b81b747ea908 (patch)
tree46a48c3f3341a7673f96bfb152c6f05703e04465 /src/normal.cc
parentb2a853cfc2e52559b70d0ad3bfc4a49f3ed16833 (diff)
Revert "Switch undo storage from a tree to a plain list"
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U> for selection undo/redo This reverts commit e0d33f51b36c9f0be7ae2467dab455d211bbf561.
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 68392199..08ce028d 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -2011,6 +2011,29 @@ void redo(Context& context, NormalParams params)
}
template<Direction direction>
+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<Direction direction>
void undo_selection_change(Context& context, NormalParams params)
{
int count = std::max(1, params.count);
@@ -2339,6 +2362,8 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {'u'}, {"undo", undo} },
{ {'U'}, {"redo", redo} },
+ { {ctrl('k')}, {"move backward in history", move_in_history<Direction::Backward>} },
+ { {ctrl('j')}, {"move forward in history", move_in_history<Direction::Forward>} },
{ {alt('u')}, {"undo selection change", undo_selection_change<Backward>} },
{ {alt('U')}, {"redo selection change", undo_selection_change<Forward>} },