Skip to content

Commit

Permalink
Fix cmdline confirmation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Nov 10, 2021
1 parent 6071062 commit b3ee713
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lua/cmp/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit b3ee713

Please sign in to comment.