Skip to content

Commit ec72a3a

Browse files
committed
feature(pick): make key query process respect the 'iminsert' option
The 'getcharstr' returns a character from the input as is, and it is not affected by the 'iminsert' option. It is possible, however, to construct a lookup table for ':lmap' mappings and apply it to the returned character on the fly. This successfully emulates the 'iminsert' option in the 'mini.pick' input field. However, the 'iminsert' toggle has to be defined in 'mini.pick' configuration as a keybinding, as the standard '<C-^>' has no effect by default. The lookup table is created only once and then cached. In my non-scientific testing, thie feature has no impact on input latency. The feature has no effect if the 'keymap' option is not set. I understand that 'iminsert' is a relatively niche feature to cover, and it was never mentioned in issues or discussions. While you can always change the keyboard layout, and achieve the desired effect, it feels unnatural to me. I write quite a lot in the 'iminsert' mode, and find it easier to invoke than the keyboard layout change. I thought to raise the issue beforehand, but the implementation is quite trivial, so I decided to raise the PR outright. I intentionally did not update the documentation or anything. If you want to move forward with the feature, I am ready and willing to follow your lead and bring the change up to standard.
1 parent d12b7c1 commit ec72a3a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

lua/mini/pick.lua

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,33 @@ H.redraw = function() vim.cmd('redraw') end
35723572

35733573
H.redraw_scheduled = vim.schedule_wrap(H.redraw)
35743574

3575+
-- Minimal config
3576+
-- require("mini.pick").setup {
3577+
-- mappings = {
3578+
-- iminsert = {
3579+
-- char = "<C-^>",
3580+
-- func = function()
3581+
-- vim.cmd "let &l:iminsert = xor(&l:iminsert, 1)"
3582+
-- vim.notify("'iminsert' is now " .. vim.o.iminsert)
3583+
-- end,
3584+
-- },
3585+
-- },
3586+
-- }
3587+
3588+
---@return table<string, string>
3589+
function H.lmap()
3590+
if H._lmap == nil then
3591+
H._lmap = vim
3592+
.iter(ipairs(vim.fn.maplist()))
3593+
:filter(function(_, map) return map.mode == 'l' end)
3594+
:fold({}, function(acc, _, map)
3595+
acc[map.lhs] = map.rhs
3596+
return acc
3597+
end)
3598+
end
3599+
return H._lmap
3600+
end
3601+
35753602
H.getcharstr = function(delay_async)
35763603
-- Ensure that redraws still happen
35773604
H.timers.getcharstr:start(0, delay_async, H.redraw_scheduled)
@@ -3585,7 +3612,11 @@ H.getcharstr = function(delay_async)
35853612
if H.pickers.active ~= nil then main_win_id = H.pickers.active.windows.main end
35863613
local is_bad_mouse_click = vim.v.mouse_winid ~= 0 and vim.v.mouse_winid ~= main_win_id
35873614
if not ok or char == '' or char == '\3' or is_bad_mouse_click then return end
3588-
return char
3615+
if vim.o.keymap ~= '' and vim.o.iminsert ~= 0 then
3616+
return H.lmap()[char] or char
3617+
else
3618+
return char
3619+
end
35893620
end
35903621

35913622
H.tolower = (function()

0 commit comments

Comments
 (0)