Fix cmdline confirmation
This commit is contained in:
@@ -372,23 +372,34 @@ core.confirm = function(self, e, option, callback)
|
|||||||
completion_item.textEdit.range = e:get_insert_range()
|
completion_item.textEdit.range = e:get_insert_range()
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_snippet = completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet
|
local diff_before = e.context.cursor.character - completion_item.textEdit.range.start.character
|
||||||
|
local diff_after = completion_item.textEdit.range['end'].character - e.context.cursor.character
|
||||||
local new_text = completion_item.textEdit.newText
|
local new_text = completion_item.textEdit.newText
|
||||||
completion_item.textEdit.range.start.line = ctx.cursor.line
|
|
||||||
completion_item.textEdit.range.start.character = ctx.cursor.character - (e.context.cursor.character - completion_item.textEdit.range.start.character)
|
if api.is_insert_mode() then
|
||||||
completion_item.textEdit.range['end'].line = ctx.cursor.line
|
local is_snippet = completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet
|
||||||
completion_item.textEdit.range['end'].character = ctx.cursor.character + (completion_item.textEdit.range['end'].character - e.context.cursor.character)
|
completion_item.textEdit.range.start.line = ctx.cursor.line
|
||||||
if is_snippet then
|
completion_item.textEdit.range.start.character = ctx.cursor.character - diff_before
|
||||||
completion_item.textEdit.newText = ''
|
completion_item.textEdit.range['end'].line = ctx.cursor.line
|
||||||
|
completion_item.textEdit.range['end'].character = ctx.cursor.character + diff_after
|
||||||
|
if is_snippet then
|
||||||
|
completion_item.textEdit.newText = ''
|
||||||
|
end
|
||||||
|
vim.fn['cmp#apply_text_edits'](ctx.bufnr, { completion_item.textEdit })
|
||||||
|
if is_snippet then
|
||||||
|
config.get().snippet.expand({
|
||||||
|
body = new_text,
|
||||||
|
insert_text_mode = completion_item.insertTextMode,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
next()
|
||||||
|
else
|
||||||
|
local keys = {}
|
||||||
|
table.insert(keys, string.rep(keymap.t('<BS>'), diff_before))
|
||||||
|
table.insert(keys, string.rep(keymap.t('<Del>'), diff_after))
|
||||||
|
table.insert(keys, new_text)
|
||||||
|
feedkeys.call(table.concat(keys, ''), 'n', next)
|
||||||
end
|
end
|
||||||
vim.fn['cmp#apply_text_edits'](ctx.bufnr, { completion_item.textEdit })
|
|
||||||
if is_snippet then
|
|
||||||
config.get().snippet.expand({
|
|
||||||
body = new_text,
|
|
||||||
insert_text_mode = completion_item.insertTextMode,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
next()
|
|
||||||
|
|
||||||
-- Finalize
|
-- Finalize
|
||||||
end, function()
|
end, function()
|
||||||
|
|||||||
39
lua/cmp/utils/api_spec.lua
Normal file
39
lua/cmp/utils/api_spec.lua
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
local spec = require('cmp.utils.spec')
|
||||||
|
local keymap = require('cmp.utils.keymap')
|
||||||
|
local feedkeys = require('cmp.utils.feedkeys')
|
||||||
|
local api = require('cmp.utils.api')
|
||||||
|
|
||||||
|
describe('api', function()
|
||||||
|
describe('get_cursor', function()
|
||||||
|
before_each(spec.before)
|
||||||
|
it('insert-mode', function()
|
||||||
|
feedkeys.call(keymap.t('i\t1234567890'), 'n', function()
|
||||||
|
assert.are.same(api.get_cursor()[2], 10)
|
||||||
|
end)
|
||||||
|
feedkeys.call('', 'nx')
|
||||||
|
end)
|
||||||
|
it('cmdline-mode', function()
|
||||||
|
feedkeys.call(keymap.t(':\t1234567890'), 'n', function()
|
||||||
|
assert.are.same(api.get_cursor()[2], 10)
|
||||||
|
end)
|
||||||
|
feedkeys.call('', 'nx')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('get_cursor_before_line', function()
|
||||||
|
before_each(spec.before)
|
||||||
|
it('insert-mode', function()
|
||||||
|
feedkeys.call(keymap.t(':\t1234567890<Left><Left>'), 'n', function()
|
||||||
|
assert.are.same(api.get_cursor_before_line(), '\t12345678')
|
||||||
|
end)
|
||||||
|
feedkeys.call('', 'nx')
|
||||||
|
end)
|
||||||
|
it('cmdline-mode', function()
|
||||||
|
feedkeys.call(keymap.t(':\t1234567890<Left><Left>'), 'n', function()
|
||||||
|
assert.are.same(api.get_cursor_before_line(), '\t12345678')
|
||||||
|
end)
|
||||||
|
feedkeys.call('', 'nx')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ feedkeys.call = setmetatable({
|
|||||||
table.insert(queue, { keymap.t('<Cmd>set %slazyredraw<CR>'):format(vim.o.lazyredraw and '' or 'no'), 'n' })
|
table.insert(queue, { keymap.t('<Cmd>set %slazyredraw<CR>'):format(vim.o.lazyredraw and '' or 'no'), 'n' })
|
||||||
table.insert(queue, { keymap.t('<Cmd>set eventignore=%s<CR>'):format(vim.o.eventignore or ''), 'n' })
|
table.insert(queue, { keymap.t('<Cmd>set eventignore=%s<CR>'):format(vim.o.eventignore or ''), 'n' })
|
||||||
end
|
end
|
||||||
if #keys > 0 or callback then
|
if callback then
|
||||||
local id = misc.id('cmp.utils.feedkeys.call')
|
local id = misc.id('cmp.utils.feedkeys.call')
|
||||||
self.callbacks[id] = function()
|
self.callbacks[id] = function()
|
||||||
if callback then
|
if callback then
|
||||||
|
|||||||
@@ -7,17 +7,9 @@ describe('feedkeys', function()
|
|||||||
before_each(spec.before)
|
before_each(spec.before)
|
||||||
|
|
||||||
it('dot-repeat', function()
|
it('dot-repeat', function()
|
||||||
feedkeys.call(keymap.t('iaiueo<Esc>'), 'nx')
|
feedkeys.call(keymap.t('iaiueo<Esc>'), 'n', function()
|
||||||
assert.are.equal(vim.fn.getreg('.'), keymap.t('aiueo'))
|
assert.are.equal(vim.fn.getreg('.'), keymap.t('aiueo'))
|
||||||
end)
|
|
||||||
it('macro', function()
|
|
||||||
vim.fn.setreg('q', '')
|
|
||||||
vim.cmd([[normal! qq]])
|
|
||||||
feedkeys.call(keymap.t('iaiueo'), 'nt')
|
|
||||||
feedkeys.call(keymap.t('<Esc>'), 'nt', function()
|
|
||||||
vim.cmd([[normal! q]])
|
|
||||||
assert.are.equal(vim.fn.getreg('q'), keymap.t('iaiueo<Esc>'))
|
|
||||||
print(vim.fn.getreg('q'))
|
|
||||||
end)
|
end)
|
||||||
|
feedkeys.call('', 'nx')
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ describe('keymap', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
describe('realworld', function()
|
describe('realworld', function()
|
||||||
|
before_each(spec.before)
|
||||||
it('#226', function()
|
it('#226', function()
|
||||||
keymap.listen('i', '<c-n>', function(_, fallback)
|
keymap.listen('i', '<c-n>', function(_, fallback)
|
||||||
fallback()
|
fallback()
|
||||||
|
|||||||
@@ -8,9 +8,21 @@ spec.before = function()
|
|||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
bdelete!
|
bdelete!
|
||||||
enew!
|
enew!
|
||||||
|
imapclear
|
||||||
|
imapclear <buffer>
|
||||||
|
cmapclear
|
||||||
|
cmapclear <buffer>
|
||||||
|
smapclear
|
||||||
|
smapclear <buffer>
|
||||||
|
xmapclear
|
||||||
|
xmapclear <buffer>
|
||||||
|
tmapclear
|
||||||
|
tmapclear <buffer>
|
||||||
|
setlocal noswapfile
|
||||||
setlocal virtualedit=all
|
setlocal virtualedit=all
|
||||||
setlocal completeopt=menu,menuone,noselect
|
setlocal completeopt=menu,menuone,noselect
|
||||||
]])
|
]])
|
||||||
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, true, true), 'x', true)
|
||||||
end
|
end
|
||||||
|
|
||||||
spec.state = function(text, row, col)
|
spec.state = function(text, row, col)
|
||||||
|
|||||||
Reference in New Issue
Block a user