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));
|
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);
|
auto ref = buffer.string(m_completions.begin, m_completions.end);
|
||||||
|
Vector<Selection> ranges;
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
const auto& cursor = sel.cursor();
|
const auto& cursor = sel.cursor();
|
||||||
auto pos = buffer.iterator_at(cursor);
|
auto pos = buffer.iterator_at(cursor);
|
||||||
if (cursor.column >= prefix_len and (pos + suffix_len) != buffer.end() and
|
if (cursor.column >= prefix_len and (pos + suffix_len) != buffer.end() and
|
||||||
std::equal(ref.begin(), ref.end(), pos - prefix_len))
|
std::equal(ref.begin(), ref.end(), pos - prefix_len))
|
||||||
{
|
ranges.push_back({(pos - prefix_len).coord(), (pos + suffix_len - 1).coord()});
|
||||||
buffer.replace((pos - prefix_len).coord(),
|
}
|
||||||
(pos + suffix_len).coord(), candidate.completion);
|
if (not ranges.empty())
|
||||||
|
SelectionList{buffer, std::move(ranges)}.insert(candidate.completion, InsertMode::Replace);
|
||||||
selections.update();
|
selections.update();
|
||||||
}
|
|
||||||
}
|
|
||||||
m_completions.end = cursor_pos;
|
m_completions.end = cursor_pos;
|
||||||
m_completions.begin = buffer.advance(cursor_pos, -candidate.completion.length());
|
m_completions.begin = buffer.advance(cursor_pos, -candidate.completion.length());
|
||||||
m_completions.timestamp = buffer.timestamp();
|
m_completions.timestamp = buffer.timestamp();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user