diff --git a/src/insert_completer.cc b/src/insert_completer.cc index c2659579..789cb0eb 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -373,18 +373,19 @@ void InsertCompleter::select(int offset, Vector& keystrokes) const auto suffix_len = std::max(0_byte, buffer.distance(cursor_pos, m_completions.end)); auto ref = buffer.string(m_completions.begin, m_completions.end); + Vector ranges; for (auto& sel : selections) { const auto& cursor = sel.cursor(); auto pos = buffer.iterator_at(cursor); if (cursor.column >= prefix_len and (pos + suffix_len) != buffer.end() and std::equal(ref.begin(), ref.end(), pos - prefix_len)) - { - buffer.replace((pos - prefix_len).coord(), - (pos + suffix_len).coord(), candidate.completion); - selections.update(); - } + ranges.push_back({(pos - prefix_len).coord(), (pos + suffix_len - 1).coord()}); } + if (not ranges.empty()) + SelectionList{buffer, std::move(ranges)}.insert(candidate.completion, InsertMode::Replace); + selections.update(); + m_completions.end = cursor_pos; m_completions.begin = buffer.advance(cursor_pos, -candidate.completion.length()); m_completions.timestamp = buffer.timestamp();