add normal mode in compile-mode and find-file

This commit is contained in:
Ray Andrew 2025-11-20 01:47:59 -06:00
parent 363170e4ad
commit bce9fac052
Signed by: rayandrew
SSH key fingerprint: SHA256:XYrYrxF0Z3A72n8P/p6mqPRNQZT22F88XcLsG+kX4xw
2 changed files with 22 additions and 9 deletions

View file

@ -684,7 +684,7 @@ function M.compile()
-- Cycle to next completion candidate
if config.input_keymaps.next then
vim.keymap.set('i', config.input_keymaps.next, function()
local next_fn = function()
if #matches == 0 then
matches = get_matches(current_input)
if #matches == 0 then return end
@ -696,12 +696,14 @@ function M.compile()
current_input = table.concat(words, ' ')
last_input = current_input
vim.schedule(update_display)
end, opts)
end
vim.keymap.set('i', config.input_keymaps.next, next_fn, opts)
vim.keymap.set('n', config.input_keymaps.next, next_fn, opts)
end
-- Cycle to previous completion candidate
if config.input_keymaps.prev then
vim.keymap.set('i', config.input_keymaps.prev, function()
local prev_fn = function()
if #matches == 0 then
matches = get_matches(current_input)
if #matches == 0 then return end
@ -714,7 +716,9 @@ function M.compile()
current_input = table.concat(words, ' ')
last_input = current_input
vim.schedule(update_display)
end, opts)
end
vim.keymap.set('i', config.input_keymaps.prev, prev_fn, opts)
vim.keymap.set('n', config.input_keymaps.prev, prev_fn, opts)
end
-- Complete to selected candidate
@ -790,7 +794,12 @@ function M.compile()
local close_keys = type(config.input_keymaps.close) == 'table' and config.input_keymaps.close --[[@as string[] ]]
or { config.input_keymaps.close }
for _, key in ipairs(close_keys) do
if key then vim.keymap.set({ 'i', 'n' }, key, function() vim.schedule(close) end, opts) end
if key then
-- In insert mode: exit to normal mode first
vim.keymap.set('i', key, '<Esc>', opts)
-- In normal mode: close the prompt
vim.keymap.set('n', key, function() vim.schedule(close) end, opts)
end
end
-- Delete path component

View file

@ -332,7 +332,7 @@ function M.open_dir(start_path)
local last_input = current_input
vim.api.nvim_create_autocmd({ 'TextChangedI' }, {
vim.api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI' }, {
buffer = input_buf,
callback = function()
if lock or cycling then return end
@ -354,7 +354,7 @@ function M.open_dir(start_path)
end,
})
vim.api.nvim_create_autocmd({ 'CursorMovedI' }, {
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = input_buf,
callback = function()
if lock or cycling then return end
@ -456,9 +456,13 @@ function M.open_dir(start_path)
end, { buffer = input_buf, nowait = true, expr = true, desc = 'Open file or directory' })
---@type string[]
local close_keys = type(config.keymaps.close) == 'table' and config.keymaps.close --[[@as string[] ]] or { config.keymaps.close }
local close_keys = type(config.keymaps.close) == 'table' and config.keymaps.close --[[@as string[] ]]
or { config.keymaps.close }
for _, key in ipairs(close_keys) do
vim.keymap.set({ 'n', 'i' }, key, function() vim.schedule(close) end, vim.tbl_extend('force', opts, { desc = 'Close find-file' }))
-- In insert mode: exit to normal mode first
vim.keymap.set('i', key, '<Esc>', vim.tbl_extend('force', opts, { desc = 'Exit to normal mode' }))
-- In normal mode: close the prompt
vim.keymap.set('n', key, function() vim.schedule(close) end, vim.tbl_extend('force', opts, { desc = 'Close find-file' }))
end
vim.keymap.set('i', config.keymaps.delete_component, function()