1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-23 19:46:33 +03:00

Detect no-op replaces and do not act on them

This avoids recording no-op undo groups.
This commit is contained in:
Maxime Coste 2018-03-09 23:07:05 +11:00
parent 950e24949a
commit 9125b01fa8
2 changed files with 7 additions and 2 deletions

View File

@ -613,6 +613,9 @@ BufferCoord Buffer::replace(BufferCoord begin, BufferCoord end, StringView conte
content = content.substr(0, content.length() - 1); content = content.substr(0, content.length() - 1);
} }
if (std::equal(iterator_at(begin), iterator_at(end), content.begin(), content.end()))
return begin;
auto pos = erase(begin, end); auto pos = erase(begin, end);
return insert(pos, content); return insert(pos, content);
} }

View File

@ -411,9 +411,9 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
if (mode == InsertMode::Replace) if (mode == InsertMode::Replace)
{ {
auto changes = m_buffer->changes_since(old_timestamp); auto changes = m_buffer->changes_since(old_timestamp);
if (changes.size() < 2) // Nothing got inserted, either str was empty, or just \n at end of buffer if (changes.size() == 1) // Nothing got inserted, either str was empty, or just \n at end of buffer
sel.anchor() = sel.cursor() = m_buffer->clamp(pos); sel.anchor() = sel.cursor() = m_buffer->clamp(pos);
else else if (changes.size() == 2)
{ {
// we want min and max from *before* we do any change // we want min and max from *before* we do any change
auto& min = sel.min(); auto& min = sel.min();
@ -421,6 +421,8 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
min = changes.back().begin; min = changes.back().begin;
max = m_buffer->char_prev(changes.back().end); max = m_buffer->char_prev(changes.back().end);
} }
else
kak_assert(changes.empty());
} }
else if (not str.empty()) else if (not str.empty())
{ {