@@ -6,13 +6,13 @@ local CTRL_S = vim.api.nvim_replace_termcodes('<C-s>', true, true, true)
|
||||
api.get_mode = function()
|
||||
local mode = vim.api.nvim_get_mode().mode:sub(1, 1)
|
||||
if mode == 'i' then
|
||||
return 'i' -- insert
|
||||
return 'i' -- insert
|
||||
elseif mode == 'v' or mode == 'V' or mode == CTRL_V then
|
||||
return 'x' -- visual
|
||||
return 'x' -- visual
|
||||
elseif mode == 's' or mode == 'S' or mode == CTRL_S then
|
||||
return 's' -- select
|
||||
return 's' -- select
|
||||
elseif mode == 'c' and vim.fn.getcmdtype() ~= '=' then
|
||||
return 'c' -- cmdline
|
||||
return 'c' -- cmdline
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -44,4 +44,3 @@ describe('api', function()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -28,7 +28,29 @@ describe('feedkeys', function()
|
||||
feedkeys.call(keymap.t('iif<CR><Tab>end') .. keymap.autoindent(), 'nx')
|
||||
assert.are.same(vim.api.nvim_buf_get_lines(0, 0, -1, false), {
|
||||
'if',
|
||||
'end'
|
||||
'end',
|
||||
})
|
||||
end)
|
||||
|
||||
it('testability', function()
|
||||
feedkeys.call('i', 'n', function()
|
||||
feedkeys.call('', 'n', function()
|
||||
feedkeys.call('aiueo', 'in')
|
||||
end)
|
||||
feedkeys.call('', 'n', function()
|
||||
feedkeys.call(keymap.t('<BS><BS><BS><BS><BS>'), 'in')
|
||||
end)
|
||||
feedkeys.call('', 'n', function()
|
||||
feedkeys.call(keymap.t('abcde'), 'in')
|
||||
end)
|
||||
feedkeys.call('', 'n', function()
|
||||
feedkeys.call(keymap.t('<BS><BS><BS><BS><BS>'), 'in')
|
||||
end)
|
||||
feedkeys.call('', 'n', function()
|
||||
feedkeys.call(keymap.t('12345'), 'in')
|
||||
end)
|
||||
end)
|
||||
feedkeys.call('', 'x')
|
||||
assert.are.same(vim.api.nvim_buf_get_lines(0, 0, -1, false), { '12345' })
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -81,7 +81,7 @@ keymap.autoindent = function()
|
||||
table.insert(keys, keymap.t('<Cmd>setlocal indentkeys+=!^F<CR>'))
|
||||
table.insert(keys, keymap.t('<C-f>'))
|
||||
table.insert(keys, keymap.t('<Cmd>setlocal %scindent<CR>'):format(vim.bo.cindent and '' or 'no'))
|
||||
table.insert(keys, keymap.t('<Cmd>setlocal indentkeys=%s<CR>'):format(vim.bo.indentkeys:gsub( '|', '\\|')))
|
||||
table.insert(keys, keymap.t('<Cmd>setlocal indentkeys=%s<CR>'):format(vim.bo.indentkeys:gsub('|', '\\|')))
|
||||
return table.concat(keys, '')
|
||||
end
|
||||
|
||||
@@ -110,9 +110,12 @@ keymap.listen = function(mode, lhs, callback)
|
||||
return vim.api.nvim_feedkeys(keymap.t(fallback.keys), fallback.mode, true)
|
||||
end
|
||||
|
||||
callback(lhs, misc.once(function()
|
||||
vim.api.nvim_feedkeys(keymap.t(fallback.keys), fallback.mode, true)
|
||||
end))
|
||||
callback(
|
||||
lhs,
|
||||
misc.once(function()
|
||||
vim.api.nvim_feedkeys(keymap.t(fallback.keys), fallback.mode, true)
|
||||
end)
|
||||
)
|
||||
end, {
|
||||
expr = false,
|
||||
noremap = true,
|
||||
@@ -237,7 +240,7 @@ end
|
||||
|
||||
---Set keymapping
|
||||
keymap.set_map = setmetatable({
|
||||
callbacks = {}
|
||||
callbacks = {},
|
||||
}, {
|
||||
__call = function(self, bufnr, mode, lhs, rhs, opts)
|
||||
if type(rhs) == 'function' then
|
||||
@@ -255,7 +258,7 @@ keymap.set_map = setmetatable({
|
||||
else
|
||||
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
misc.set(_G, { 'cmp', 'utils', 'keymap', 'set_map' }, function(id)
|
||||
return keymap.set_map.callbacks[id]() or ''
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local context = require('cmp.context')
|
||||
local source = require('cmp.source')
|
||||
local types = require('cmp.types')
|
||||
local config = require('cmp.config')
|
||||
|
||||
local spec = {}
|
||||
|
||||
@@ -22,7 +23,28 @@ spec.before = function()
|
||||
setlocal virtualedit=all
|
||||
setlocal completeopt=menu,menuone,noselect
|
||||
]])
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, true, true), 'x', true)
|
||||
config.set_global({
|
||||
sources = {
|
||||
{ name = 'spec' },
|
||||
},
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
local ctx = context.new()
|
||||
vim.api.nvim_buf_set_text(ctx.bufnr, ctx.cursor.row - 1, ctx.cursor.col - 1, ctx.cursor.row - 1, ctx.cursor.col - 1, vim.split(string.gsub(args.body, '%$0', ''), '\n'))
|
||||
for i, t in ipairs(vim.split(args.body, '\n')) do
|
||||
local s = string.find(t, '$0', 1, true)
|
||||
if s then
|
||||
if i == 1 then
|
||||
vim.api.nvim_win_set_cursor(0, { ctx.cursor.row, ctx.cursor.col + s - 2 })
|
||||
else
|
||||
vim.api.nvim_win_set_cursor(0, { ctx.cursor.row, s - 1 })
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
spec.state = function(text, row, col)
|
||||
|
||||
Reference in New Issue
Block a user