Collapse jumps based on current index change

The previous method, while likely more correct, could restore jump
lists containing references to already removed buffers.
This commit is contained in:
Maxime Coste 2019-02-17 10:19:54 +11:00
parent 924f30840b
commit 1ad3b87302
3 changed files with 16 additions and 9 deletions

View File

@ -1754,18 +1754,17 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
else else
{ {
const bool collapse_jumps = not (c.flags() & Context::Flags::Draft) and context.has_buffer(); const bool collapse_jumps = not (c.flags() & Context::Flags::Draft) and context.has_buffer();
auto original_jump_list = collapse_jumps ? c.jump_list() : Optional<JumpList>{}; auto& jump_list = c.jump_list();
const size_t prev_index = jump_list.current_index();
auto jump = collapse_jumps ? c.selections() : Optional<SelectionList>{}; auto jump = collapse_jumps ? c.selections() : Optional<SelectionList>{};
func(parser, c); func(parser, c);
// If the jump list got mutated, collapse all jumps into a single one from original selections // 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) if (auto index = jump_list.current_index();
{ collapse_jumps and index > prev_index and
original_jump_list->push(std::move(*jump)); contains(BufferManager::instance(), &jump->buffer()))
if (c.jump_list() != *original_jump_list) jump_list.push(std::move(*jump), prev_index);
c.jump_list() = std::move(*original_jump_list);
}
} }
} }

View File

@ -76,8 +76,14 @@ void Context::print_status(DisplayLine status) const
client().print_status(std::move(status)); client().print_status(std::move(status));
} }
void JumpList::push(SelectionList jump) void JumpList::push(SelectionList jump, Optional<size_t> index)
{ {
if (index)
{
m_current = *index;
kak_assert(m_current <= m_jumps.size());
}
if (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(m_jumps.begin()+m_current+1, m_jumps.end());
m_jumps.erase(std::remove(begin(m_jumps), end(m_jumps), jump), m_jumps.erase(std::remove(begin(m_jumps), end(m_jumps), jump),

View File

@ -21,7 +21,7 @@ class AliasRegistry;
struct JumpList struct JumpList
{ {
void push(SelectionList jump); void push(SelectionList jump, Optional<size_t> index = {});
const SelectionList& forward(Context& context, int count); const SelectionList& forward(Context& context, int count);
const SelectionList& backward(Context& context, int count); const SelectionList& backward(Context& context, int count);
void forget_buffer(Buffer& buffer); void forget_buffer(Buffer& buffer);
@ -33,6 +33,8 @@ struct JumpList
friend bool operator!=(const JumpList& lhs, const JumpList& rhs) { return not (lhs == rhs); } friend bool operator!=(const JumpList& lhs, const JumpList& rhs) { return not (lhs == rhs); }
size_t current_index() const { return m_current; }
private: private:
using Contents = Vector<SelectionList, MemoryDomain::Selections>; using Contents = Vector<SelectionList, MemoryDomain::Selections>;
Contents m_jumps; Contents m_jumps;