add autocompletion to multicursor (#1394)

* use Doc:remove
This commit is contained in:
vqn 2023-04-07 16:54:52 +00:00 committed by George Sokianos
parent 46ea86e28c
commit 449f7d66c3
1 changed files with 17 additions and 4 deletions

View File

@ -631,7 +631,6 @@ end
command.add(predicate, { command.add(predicate, {
["autocomplete:complete"] = function(dv) ["autocomplete:complete"] = function(dv)
local doc = dv.doc local doc = dv.doc
local line, col = doc:get_selection()
local item = suggestions[suggestions_idx] local item = suggestions[suggestions_idx]
local text = item.text local text = item.text
local inserted = false local inserted = false
@ -640,9 +639,23 @@ command.add(predicate, {
end end
if not inserted then if not inserted then
local current_partial = get_partial_symbol() local current_partial = get_partial_symbol()
doc:insert(line, col, text) local sz = #current_partial
doc:remove(line, col, line, col - #current_partial)
doc:set_selection(line, col + #text - #current_partial) for idx, line1, col1, line2, col2 in doc:get_selections(true) do
local n = col1 - 1
local line = doc.lines[line1]
for i = 1, sz + 1 do
local j = sz - i
local subline = line:sub(n - j, n)
local subpartial = current_partial:sub(i, -1)
if subpartial == subline then
doc:remove(line1, col1, line2, n - j)
break
end
end
end
doc:text_input(item.text)
end end
reset_suggestions() reset_suggestions()
end, end,