summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-09 23:07:05 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-09 23:07:05 +1100
commit9125b01fa8302c2beb61c5620ead85e24e703631 (patch)
tree115530c1cdf1092e19ea19bd64bf6278cf7b0f35 /src
parent950e24949a601a118659a95fc81c81809b36d0e9 (diff)
Detect no-op replaces and do not act on them
This avoids recording no-op undo groups.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc3
-rw-r--r--src/selection.cc6
2 files changed, 7 insertions, 2 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index d065e02e..7a476264 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -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);
}
diff --git a/src/selection.cc b/src/selection.cc
index 00280a4d..2a4a4629 100644
--- a/src/selection.cc
+++ b/src/selection.cc
@@ -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())
{