Skip to content

Commit 7304708

Browse files
committed
fix(suggestion): cursor position for nvim v0.10.x
1 parent 406f148 commit 7304708

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lua/copilot/suggestion.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ local config = require("copilot.config")
44
local hl_group = require("copilot.highlight").group
55
local util = require("copilot.util")
66

7+
local _, has_nvim_0_10_x = pcall(function()
8+
return vim.version().minor == 10
9+
end)
10+
711
local mod = {}
812

913
---@alias copilot_suggestion_context { first?: integer, cycling?: integer, cycling_callbacks?: (fun(ctx: copilot_suggestion_context):nil)[], params?: table, suggestions?: copilot_get_completions_data_completion[], choice?: integer, shown_choices?: table<string, true> }
@@ -470,7 +474,11 @@ function mod.accept(modifier)
470474
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Space><Left><Del>", true, false, true), "n", false)
471475
vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, 0, "utf-16")
472476
-- Put cursor at the end of current line.
473-
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<End>", true, false, true), "n", false)
477+
local cursor_keys = "<End>"
478+
if has_nvim_0_10_x then
479+
cursor_keys = string.rep("<Down>", #vim.split(newText, "\n", { plain = true }) - 1) .. cursor_keys
480+
end
481+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(cursor_keys, true, false, true), "n", false)
474482
end
475483

476484
function mod.accept_word()

0 commit comments

Comments
 (0)