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)