diff --git a/src/commands.cc b/src/commands.cc index 5db90b5c..5f7e1530 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1754,18 +1754,17 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d else { const bool collapse_jumps = not (c.flags() & Context::Flags::Draft) and context.has_buffer(); - auto original_jump_list = collapse_jumps ? c.jump_list() : Optional{}; + auto& jump_list = c.jump_list(); + const size_t prev_index = jump_list.current_index(); auto jump = collapse_jumps ? c.selections() : Optional{}; func(parser, c); // If the jump list got mutated, collapse all jumps into a single one from original selections - if (collapse_jumps and c.jump_list() != *original_jump_list) - { - original_jump_list->push(std::move(*jump)); - if (c.jump_list() != *original_jump_list) - c.jump_list() = std::move(*original_jump_list); - } + if (auto index = jump_list.current_index(); + collapse_jumps and index > prev_index and + contains(BufferManager::instance(), &jump->buffer())) + jump_list.push(std::move(*jump), prev_index); } } diff --git a/src/context.cc b/src/context.cc index b3b82938..d97073d0 100644 --- a/src/context.cc +++ b/src/context.cc @@ -76,8 +76,14 @@ void Context::print_status(DisplayLine status) const client().print_status(std::move(status)); } -void JumpList::push(SelectionList jump) +void JumpList::push(SelectionList jump, Optional index) { + if (index) + { + m_current = *index; + kak_assert(m_current <= m_jumps.size()); + } + if (m_current != m_jumps.size()) m_jumps.erase(m_jumps.begin()+m_current+1, m_jumps.end()); m_jumps.erase(std::remove(begin(m_jumps), end(m_jumps), jump), diff --git a/src/context.hh b/src/context.hh index d8830b2e..b71e6547 100644 --- a/src/context.hh +++ b/src/context.hh @@ -21,7 +21,7 @@ class AliasRegistry; struct JumpList { - void push(SelectionList jump); + void push(SelectionList jump, Optional index = {}); const SelectionList& forward(Context& context, int count); const SelectionList& backward(Context& context, int count); void forget_buffer(Buffer& buffer); @@ -33,6 +33,8 @@ struct JumpList friend bool operator!=(const JumpList& lhs, const JumpList& rhs) { return not (lhs == rhs); } + size_t current_index() const { return m_current; } + private: using Contents = Vector; Contents m_jumps;