Skip to content

Commit 1a237cf

Browse files
Fix E565 when using Tab as accept (zbirenbaum#284)
1 parent f165763 commit 1a237cf

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lua/copilot/suggestion.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,16 @@ function mod.accept(modifier)
484484
end
485485

486486
-- Hack for 'autoindent', makes the indent persist. Check `:help 'autoindent'`.
487-
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Space><Left><Del>", true, false, true), "n", false)
488-
vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, vim.api.nvim_get_current_buf(), "utf-16")
489-
-- Put cursor at the end of current line.
490-
local cursor_keys = "<End>"
491-
if has_nvim_0_10_x then
492-
cursor_keys = string.rep("<Down>", #vim.split(newText, "\n", { plain = true }) - 1) .. cursor_keys
493-
end
494-
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(cursor_keys, true, false, true), "n", false)
487+
vim.schedule_wrap(function()
488+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Space><Left><Del>", true, false, true), "n", false)
489+
vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, vim.api.nvim_get_current_buf(), "utf-16")
490+
-- Put cursor at the end of current line.
491+
local cursor_keys = "<End>"
492+
if has_nvim_0_10_x then
493+
cursor_keys = string.rep("<Down>", #vim.split(newText, "\n", { plain = true }) - 1) .. cursor_keys
494+
end
495+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(cursor_keys, true, false, true), "n", false)
496+
end)()
495497
end
496498

497499
function mod.accept_word()

0 commit comments

Comments
 (0)