Skip to content

Commit

Permalink
add autocompletion to multicursor (lite-xl#1394)
Browse files Browse the repository at this point in the history
* use Doc:remove
  • Loading branch information
vqns authored Apr 7, 2023
1 parent f3cfb90 commit 45e0454
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions data/plugins/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ end
command.add(predicate, {
["autocomplete:complete"] = function(dv)
local doc = dv.doc
local line, col = doc:get_selection()
local item = suggestions[suggestions_idx]
local text = item.text
local inserted = false
Expand All @@ -640,9 +639,23 @@ command.add(predicate, {
end
if not inserted then
local current_partial = get_partial_symbol()
doc:insert(line, col, text)
doc:remove(line, col, line, col - #current_partial)
doc:set_selection(line, col + #text - #current_partial)
local sz = #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
reset_suggestions()
end,
Expand Down

0 comments on commit 45e0454

Please sign in to comment.