Improve macro handling
This commit is contained in:
@@ -8,7 +8,11 @@ local WIDE_HEIGHT = 40
|
|||||||
return function()
|
return function()
|
||||||
return {
|
return {
|
||||||
enabled = function()
|
enabled = function()
|
||||||
return vim.api.nvim_buf_get_option(0, 'buftype') ~= 'prompt'
|
local disabled = false
|
||||||
|
disabled = disabled or (vim.api.nvim_buf_get_option(0, 'buftype') == 'prompt')
|
||||||
|
disabled = disabled or (vim.fn.reg_recording() ~= '')
|
||||||
|
disabled = disabled or (vim.fn.reg_executing() ~= '')
|
||||||
|
return not disabled
|
||||||
end,
|
end,
|
||||||
|
|
||||||
preselect = types.cmp.PreselectMode.Item,
|
preselect = types.cmp.PreselectMode.Item,
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ core.confirm = function(self, e, option, callback)
|
|||||||
local keys = {}
|
local keys = {}
|
||||||
table.insert(keys, keymap.backspace(ctx.cursor.character - misc.to_utfindex(ctx.cursor_line, e:get_offset())))
|
table.insert(keys, keymap.backspace(ctx.cursor.character - misc.to_utfindex(ctx.cursor_line, e:get_offset())))
|
||||||
table.insert(keys, string.sub(e.context.cursor_before_line, e:get_offset()))
|
table.insert(keys, string.sub(e.context.cursor_before_line, e:get_offset()))
|
||||||
feedkeys.call(table.concat(keys, ''), 'int')
|
feedkeys.call(table.concat(keys, ''), 'in')
|
||||||
else
|
else
|
||||||
vim.api.nvim_buf_set_text(0, ctx.cursor.row - 1, e:get_offset() - 1, ctx.cursor.row - 1, ctx.cursor.col - 1, {
|
vim.api.nvim_buf_set_text(0, ctx.cursor.row - 1, e:get_offset() - 1, ctx.cursor.row - 1, ctx.cursor.col - 1, {
|
||||||
string.sub(e.context.cursor_before_line, e:get_offset()),
|
string.sub(e.context.cursor_before_line, e:get_offset()),
|
||||||
@@ -462,7 +462,7 @@ core.confirm = function(self, e, option, callback)
|
|||||||
table.insert(keys, string.rep(keymap.t('<BS>'), diff_before))
|
table.insert(keys, string.rep(keymap.t('<BS>'), diff_before))
|
||||||
table.insert(keys, string.rep(keymap.t('<Del>'), diff_after))
|
table.insert(keys, string.rep(keymap.t('<Del>'), diff_after))
|
||||||
table.insert(keys, new_text)
|
table.insert(keys, new_text)
|
||||||
feedkeys.call(table.concat(keys, ''), 'int')
|
feedkeys.call(table.concat(keys, ''), 'in')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
feedkeys.call(keymap.indentkeys(vim.bo.indentkeys), 'n')
|
feedkeys.call(keymap.indentkeys(vim.bo.indentkeys), 'n')
|
||||||
|
|||||||
@@ -130,22 +130,17 @@ end)
|
|||||||
cmp.select_next_item = cmp.sync(function(option)
|
cmp.select_next_item = cmp.sync(function(option)
|
||||||
option = option or {}
|
option = option or {}
|
||||||
|
|
||||||
-- Hack: Ignore when executing macro.
|
|
||||||
if vim.fn.reg_executing() ~= '' then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmp.core.view:visible() then
|
if cmp.core.view:visible() then
|
||||||
local release = cmp.core:suspend()
|
local release = cmp.core:suspend()
|
||||||
cmp.core.view:select_next_item(option)
|
cmp.core.view:select_next_item(option)
|
||||||
vim.schedule(release)
|
vim.schedule(release)
|
||||||
return true
|
return true
|
||||||
elseif vim.fn.pumvisible() == 1 then
|
elseif vim.fn.pumvisible() == 1 then
|
||||||
-- Special handling for native puma. Required to facilitate key mapping processing.
|
-- Special handling for native pum. Required to facilitate key mapping processing.
|
||||||
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
||||||
feedkeys.call(keymap.t('<C-n>'), 'n')
|
feedkeys.call(keymap.t('<C-n>'), 'in')
|
||||||
else
|
else
|
||||||
feedkeys.call(keymap.t('<Down>'), 'n')
|
feedkeys.call(keymap.t('<Down>'), 'in')
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -156,22 +151,17 @@ end)
|
|||||||
cmp.select_prev_item = cmp.sync(function(option)
|
cmp.select_prev_item = cmp.sync(function(option)
|
||||||
option = option or {}
|
option = option or {}
|
||||||
|
|
||||||
-- Hack: Ignore when executing macro.
|
|
||||||
if vim.fn.reg_executing() ~= '' then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmp.core.view:visible() then
|
if cmp.core.view:visible() then
|
||||||
local release = cmp.core:suspend()
|
local release = cmp.core:suspend()
|
||||||
cmp.core.view:select_prev_item(option)
|
cmp.core.view:select_prev_item(option)
|
||||||
vim.schedule(release)
|
vim.schedule(release)
|
||||||
return true
|
return true
|
||||||
elseif vim.fn.pumvisible() == 1 then
|
elseif vim.fn.pumvisible() == 1 then
|
||||||
-- Special handling for native puma. Required to facilitate key mapping processing.
|
-- Special handling for native pum. Required to facilitate key mapping processing.
|
||||||
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
||||||
feedkeys.call(keymap.t('<C-p>'), 'n')
|
feedkeys.call(keymap.t('<C-p>'), 'in')
|
||||||
else
|
else
|
||||||
feedkeys.call(keymap.t('<Up>'), 'n')
|
feedkeys.call(keymap.t('<Up>'), 'in')
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -193,11 +183,6 @@ cmp.confirm = cmp.sync(function(option, callback)
|
|||||||
option = option or {}
|
option = option or {}
|
||||||
callback = callback or function() end
|
callback = callback or function() end
|
||||||
|
|
||||||
-- Hack: Ignore when executing macro.
|
|
||||||
if vim.fn.reg_executing() ~= '' then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
|
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
|
||||||
if e then
|
if e then
|
||||||
cmp.core:confirm(e, {
|
cmp.core:confirm(e, {
|
||||||
@@ -210,7 +195,7 @@ cmp.confirm = cmp.sync(function(option, callback)
|
|||||||
else
|
else
|
||||||
-- Special handling for native puma. Required to facilitate key mapping processing.
|
-- Special handling for native puma. Required to facilitate key mapping processing.
|
||||||
if vim.fn.complete_info({ 'selected' }).selected ~= -1 then
|
if vim.fn.complete_info({ 'selected' }).selected ~= -1 then
|
||||||
feedkeys.call(keymap.t('<C-y>'), 'n')
|
feedkeys.call(keymap.t('<C-y>'), 'in')
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -106,7 +106,9 @@ keymap.listen = function(mode, lhs, callback)
|
|||||||
local bufnr = existing.buffer and vim.api.nvim_get_current_buf() or -1
|
local bufnr = existing.buffer and vim.api.nvim_get_current_buf() or -1
|
||||||
local fallback = keymap.fallback(bufnr, mode, existing)
|
local fallback = keymap.fallback(bufnr, mode, existing)
|
||||||
keymap.set_map(bufnr, mode, lhs, function()
|
keymap.set_map(bufnr, mode, lhs, function()
|
||||||
if mode == 'c' and vim.fn.getcmdtype() == '=' then
|
local ignore = false
|
||||||
|
ignore = ignore or (mode == 'c' and vim.fn.getcmdtype() == '=')
|
||||||
|
if ignore then
|
||||||
fallback()
|
fallback()
|
||||||
else
|
else
|
||||||
callback(lhs, misc.once(fallback))
|
callback(lhs, misc.once(fallback))
|
||||||
@@ -132,7 +134,7 @@ keymap.fallback = function(bufnr, mode, map)
|
|||||||
nowait = map.nowait,
|
nowait = map.nowait,
|
||||||
silent = map.silent and mode ~= 'c',
|
silent = map.silent and mode ~= 'c',
|
||||||
})
|
})
|
||||||
vim.api.nvim_feedkeys(keymap.t(fallback_expr), 'itm', true)
|
vim.api.nvim_feedkeys(keymap.t(fallback_expr), 'im', true)
|
||||||
elseif not map.callback then
|
elseif not map.callback then
|
||||||
local solved = keymap.solve(bufnr, mode, map)
|
local solved = keymap.solve(bufnr, mode, map)
|
||||||
vim.api.nvim_feedkeys(solved.keys, solved.mode, true)
|
vim.api.nvim_feedkeys(solved.keys, solved.mode, true)
|
||||||
@@ -148,7 +150,7 @@ keymap.solve = function(bufnr, mode, map)
|
|||||||
local rhs = map.expr and (map.callback and map.callback() or vim.api.nvim_eval(keymap.t(map.rhs))) or keymap.t(map.rhs)
|
local rhs = map.expr and (map.callback and map.callback() or vim.api.nvim_eval(keymap.t(map.rhs))) or keymap.t(map.rhs)
|
||||||
|
|
||||||
if map.noremap then
|
if map.noremap then
|
||||||
return { keys = rhs, mode = 'itn' }
|
return { keys = rhs, mode = 'in' }
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.find(rhs, lhs, 1, true) == 1 then
|
if string.find(rhs, lhs, 1, true) == 1 then
|
||||||
@@ -159,9 +161,9 @@ keymap.solve = function(bufnr, mode, map)
|
|||||||
nowait = map.nowait,
|
nowait = map.nowait,
|
||||||
silent = map.silent and mode ~= 'c',
|
silent = map.silent and mode ~= 'c',
|
||||||
})
|
})
|
||||||
return { keys = keymap.t(recursive) .. string.gsub(rhs, '^' .. vim.pesc(lhs), ''), mode = 'itm' }
|
return { keys = keymap.t(recursive) .. string.gsub(rhs, '^' .. vim.pesc(lhs), ''), mode = 'im' }
|
||||||
end
|
end
|
||||||
return { keys = rhs, mode = 'itm' }
|
return { keys = rhs, mode = 'im' }
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get map
|
---Get map
|
||||||
|
|||||||
Reference in New Issue
Block a user