summaryrefslogtreecommitdiff
path: root/src
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
parent03a4b3c73ff8cf7d37387df8bd0fcf9e895b59e0 (diff)
Support for going backward/forward in buffer history with <a-u>/<a-U>
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc5
-rw-r--r--src/buffer.hh1
-rw-r--r--src/normal.cc22
3 files changed, 27 insertions, 1 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 028f9516..ec970676 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -425,6 +425,11 @@ bool Buffer::move_to(size_t history_id) noexcept
return true;
}
+size_t Buffer::current_history_id() const noexcept
+{
+ return m_history_cursor->id;
+}
+
void Buffer::check_invariant() const
{
#ifdef KAK_DEBUG
diff --git a/src/buffer.hh b/src/buffer.hh
index 4cd99c8d..845d04b1 100644
--- a/src/buffer.hh
+++ b/src/buffer.hh
@@ -135,6 +135,7 @@ public:
bool undo(size_t count = 1) noexcept;
bool redo(size_t count = 1) noexcept;
bool move_to(size_t history_id) noexcept;
+ size_t current_history_id() const noexcept;
String string(ByteCoord begin, ByteCoord end) const;
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> },