summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-07-20 20:29:45 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-07-24 21:25:05 +0100
commit087a17eb24059da1a98596bb5c8e9064a72776f4 (patch)
tree39d252b0bed06ecd9db6e0ac5e704ae7424f948d /src/normal.cc
parent03a4b3c73ff8cf7d37387df8bd0fcf9e895b59e0 (diff)
Support for going backward/forward in buffer history with <a-u>/<a-U>
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 316fc5e2..544fa08f 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1431,7 +1431,6 @@ void undo(Context& context, NormalParams params)
void redo(Context& context, NormalParams params)
{
- using namespace std::placeholders;
Buffer& buffer = context.buffer();
size_t timestamp = buffer.timestamp();
if (buffer.redo(std::max(1, params.count)))
@@ -1445,6 +1444,25 @@ void redo(Context& context, NormalParams params)
context.print_status({ "nothing left to redo", get_face("Information") });
}
+template<Direction direction>
+void move_in_history(Context& context, NormalParams params)
+{
+ Buffer& buffer = context.buffer();
+ size_t timestamp = buffer.timestamp();
+ const size_t count = (size_t)std::max(1, params.count);
+ const size_t history_id = buffer.current_history_id() +
+ (direction == Direction::Forward ? count : -count);
+ if (buffer.move_to(history_id))
+ {
+ auto ranges = compute_modified_ranges(buffer, timestamp);
+ if (not ranges.empty())
+ context.selections_write_only() = std::move(ranges);
+ context.selections().avoid_eol();
+ }
+ else
+ context.print_status({ "nothing left to redo", get_face("Information") });
+}
+
void exec_user_mappings(Context& context, NormalParams params)
{
on_next_key_with_autoinfo(context, KeymapMode::None,
@@ -1679,6 +1697,8 @@ static NormalCmdDesc cmds[] =
{ 'u', "undo", undo },
{ 'U', "redo", redo },
+ { alt('u'), "move backward in history", move_in_history<Direction::Backward> },
+ { alt('U'), "move forward in history", move_in_history<Direction::Forward> },
{ alt('i'), "select inner object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner> },
{ alt('a'), "select whole object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd> },