Fix quadratic behaviour in when selecting an insert completion
Use the fast, linear time SelectionList::insert algorithm instead of an ad-hoc one that needs to call SelectionList::update after each modification of the buffer. Fixes #1417
This commit is contained in:
parent
4ab40af3a9
commit
ad9b090ddf
|
@ -373,18 +373,19 @@ void InsertCompleter::select(int offset, Vector<Key>& 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<Selection> 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);
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user