diff --git a/src/buffer.cc b/src/buffer.cc index d065e02e4..7a4762647 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 00280a4d9..2a4a4629b 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -411,9 +411,9 @@ void SelectionList::insert(ConstArrayView 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 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()) {