Support for going backward/forward in buffer history with <a-u>/<a-U>
This commit is contained in:
parent
03a4b3c73f
commit
087a17eb24
|
@ -425,6 +425,11 @@ bool Buffer::move_to(size_t history_id) noexcept
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Buffer::current_history_id() const noexcept
|
||||||
|
{
|
||||||
|
return m_history_cursor->id;
|
||||||
|
}
|
||||||
|
|
||||||
void Buffer::check_invariant() const
|
void Buffer::check_invariant() const
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
|
|
|
@ -135,6 +135,7 @@ public:
|
||||||
bool undo(size_t count = 1) noexcept;
|
bool undo(size_t count = 1) noexcept;
|
||||||
bool redo(size_t count = 1) noexcept;
|
bool redo(size_t count = 1) noexcept;
|
||||||
bool move_to(size_t history_id) noexcept;
|
bool move_to(size_t history_id) noexcept;
|
||||||
|
size_t current_history_id() const noexcept;
|
||||||
|
|
||||||
String string(ByteCoord begin, ByteCoord end) const;
|
String string(ByteCoord begin, ByteCoord end) const;
|
||||||
|
|
||||||
|
|
|
@ -1431,7 +1431,6 @@ void undo(Context& context, NormalParams params)
|
||||||
|
|
||||||
void redo(Context& context, NormalParams params)
|
void redo(Context& context, NormalParams params)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
|
||||||
Buffer& buffer = context.buffer();
|
Buffer& buffer = context.buffer();
|
||||||
size_t timestamp = buffer.timestamp();
|
size_t timestamp = buffer.timestamp();
|
||||||
if (buffer.redo(std::max(1, params.count)))
|
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") });
|
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)
|
void exec_user_mappings(Context& context, NormalParams params)
|
||||||
{
|
{
|
||||||
on_next_key_with_autoinfo(context, KeymapMode::None,
|
on_next_key_with_autoinfo(context, KeymapMode::None,
|
||||||
|
@ -1679,6 +1697,8 @@ static NormalCmdDesc cmds[] =
|
||||||
|
|
||||||
{ 'u', "undo", undo },
|
{ 'u', "undo", undo },
|
||||||
{ 'U', "redo", redo },
|
{ '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('i'), "select inner object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner> },
|
||||||
{ alt('a'), "select whole object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd> },
|
{ alt('a'), "select whole object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd> },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user