This commit is contained in:
hrsh7th
2021-11-10 04:28:32 +09:00
parent faaf1c9629
commit 6071062289
2 changed files with 11 additions and 12 deletions

View File

@@ -308,21 +308,20 @@ core.confirm = function(self, e, option, callback)
-- Close menus. -- Close menus.
self.view:close() self.view:close()
-- Simulate `<C-y>` behavior. -- Simulate <C-y> behavior and store the `.` register.
async.step(function(next) async.step(function(next)
local ctx = context.new() local ctx = context.new()
local confirm = {} local keys = {}
table.insert(confirm, keymap.backspace(ctx.cursor.character - misc.to_utfindex(e.context.cursor_before_line, e:get_offset()))) table.insert(keys, keymap.backspace(ctx.cursor.character - vim.str_utfindex(ctx.cursor_line, e:get_offset() - 1)))
table.insert(confirm, e:get_word()) table.insert(keys, e:get_word())
table.insert(confirm, keymap.undobreak()) table.insert(keys, keymap.undobreak())
feedkeys.call(table.concat(confirm, ''), 'nt', next) feedkeys.call(table.concat(keys, ''), 'nt', next)
-- Restore to the requested state. -- Restore the state again without modify the `.` register.
end, function(next) end, function(next)
local restore = {} vim.api.nvim_set_current_line(e.context.cursor_line)
table.insert(restore, keymap.backspace(vim.str_utfindex(e:get_word()))) vim.api.nvim_win_set_cursor(0, { e.context.cursor.row, e.context.cursor.col - 1 })
table.insert(restore, string.sub(e.context.cursor_before_line, e:get_offset())) next()
feedkeys.call(table.concat(restore, ''), 'n', next)
-- Async additionalTextEdits @see https://github.com/microsoft/vscode/blob/main/src/vs/editor/contrib/suggest/suggestController.ts#L334 -- Async additionalTextEdits @see https://github.com/microsoft/vscode/blob/main/src/vs/editor/contrib/suggest/suggestController.ts#L334
end, function(next) end, function(next)

View File

@@ -69,7 +69,7 @@ keymap.backspace = function(count)
return '' return ''
end end
local keys = {} local keys = {}
table.insert(keys, keymap.t(string.rep(keymap.undojoin() .. '<Left><Del>', count))) table.insert(keys, keymap.t(string.rep('<BS>', count)))
return table.concat(keys, '') return table.concat(keys, '')
end end