From b3ee713d9b8f7c6dc0f8d0f2449c7c8c7f9b71b2 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Wed, 10 Nov 2021 14:12:28 +0900 Subject: [PATCH] Fix cmdline confirmation bug --- lua/cmp/core.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index edd4c93..cc8984f 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -297,7 +297,7 @@ core.filter = async.throttle( ---@param callback function core.confirm = function(self, e, option, callback) if not (e and not e.confirmed) then - return + return callback() end e.confirmed = true @@ -319,9 +319,17 @@ core.confirm = function(self, e, option, callback) -- Restore the state again without modify the `.` register. end, function(next) - vim.api.nvim_set_current_line(e.context.cursor_line) - vim.api.nvim_win_set_cursor(0, { e.context.cursor.row, e.context.cursor.col - 1 }) - next() + if api.is_cmdline_mode() then + local ctx = context.new() + local keys = {} + table.insert(keys, keymap.backspace(ctx.cursor.character - vim.str_utfindex(ctx.cursor_line, e:get_offset() - 1))) + table.insert(keys, string.sub(e.context.cursor_before_line, e:get_offset())) + feedkeys.call(table.concat(keys, ''), 'nt', next) + else + vim.api.nvim_set_current_line(e.context.cursor_line) + vim.api.nvim_win_set_cursor(0, { e.context.cursor.row, e.context.cursor.col - 1 }) + next() + end -- Async additionalTextEdits @see https://github.com/microsoft/vscode/blob/main/src/vs/editor/contrib/suggest/suggestController.ts#L334 end, function(next)