mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-23 11:32:20 +03:00
Detect no-op replaces and do not act on them
This avoids recording no-op undo groups.
This commit is contained in:
parent
950e24949a
commit
9125b01fa8
@ -613,6 +613,9 @@ BufferCoord Buffer::replace(BufferCoord begin, BufferCoord end, StringView conte
|
||||
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);
|
||||
return insert(pos, content);
|
||||
}
|
||||
|
@ -411,9 +411,9 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
|
||||
if (mode == InsertMode::Replace)
|
||||
{
|
||||
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);
|
||||
else
|
||||
else if (changes.size() == 2)
|
||||
{
|
||||
// we want min and max from *before* we do any change
|
||||
auto& min = sel.min();
|
||||
@ -421,6 +421,8 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
|
||||
min = changes.back().begin;
|
||||
max = m_buffer->char_prev(changes.back().end);
|
||||
}
|
||||
else
|
||||
kak_assert(changes.empty());
|
||||
}
|
||||
else if (not str.empty())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user