Skip to content

Commit 8535cfc

Browse files
committed
(mini.clue) Make it work with <F*> keys as trigger.
1 parent ab94192 commit 8535cfc

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lua/mini/clue.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ H.map_trigger = function(buf_id, trigger)
12451245

12461246
-- Compute mapping RHS
12471247
trigger.keys = H.replace_termcodes(trigger.keys)
1248+
local keys_trans = H.keytrans(trigger.keys)
12481249

12491250
local rhs = function()
12501251
-- Don't act if for some reason entered the same trigger during state exec
@@ -1268,11 +1269,11 @@ H.map_trigger = function(buf_id, trigger)
12681269

12691270
-- Use buffer-local mappings and `nowait` to make it a primary source of
12701271
-- keymap execution
1271-
local desc = string.format('Query keys after "%s"', H.keytrans(trigger.keys))
1272+
local desc = string.format('Query keys after "%s"', keys_trans)
12721273
local opts = { buffer = buf_id, nowait = true, desc = desc }
12731274

1274-
-- Create mapping
1275-
vim.keymap.set(trigger.mode, trigger.keys, rhs, opts)
1275+
-- Create mapping. Use translated variant to make it work with <F*> keys.
1276+
vim.keymap.set(trigger.mode, keys_trans, rhs, opts)
12761277
end
12771278

12781279
H.unmap_trigger = function(buf_id, trigger)
@@ -1879,7 +1880,9 @@ end
18791880

18801881
H.replace_termcodes = function(x)
18811882
if x == nil then return nil end
1882-
return vim.api.nvim_replace_termcodes(x, true, true, true)
1883+
-- Use `keytrans` prior replacing termcodes to work correctly on already
1884+
-- replaced variant of `<F*>` keys
1885+
return vim.api.nvim_replace_termcodes(H.keytrans(x), true, true, true)
18831886
end
18841887

18851888
-- TODO: Remove after compatibility with Neovim=0.7 is dropped

tests/test_clue.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,25 @@ T['Reproducing keys']["respects 'clipboard'"] = function()
29702970
validate_clipboard('unnamedplus,unnamed')
29712971
end
29722972

2973+
T['Reproducing keys']['works with <F*> keys'] = function()
2974+
if child.fn.has('nvim-0.8') == 0 then MiniTest.skip('Neovim 0.7 has issues with <F*> keys.') end
2975+
2976+
child.lua([[vim.g.mapleader = vim.api.nvim_replace_termcodes('<F2>', true, true, true)]])
2977+
child.cmd('nnoremap <Leader>a <Cmd>lua _G.n = (_G.n or 0) + 1<CR>')
2978+
child.cmd('nnoremap <F3>b <Cmd>lua _G.m = (_G.m or 0) + 1<CR>')
2979+
2980+
load_module({
2981+
clues = { { mode = 'n', keys = '<Leader>a', postkeys = '<Leader>' } },
2982+
triggers = { { mode = 'n', keys = '<Leader>' }, { mode = 'n', keys = '<F3>' } },
2983+
})
2984+
2985+
type_keys('<F2>', 'a', 'a', '<Esc>')
2986+
eq(child.lua_get('_G.n'), 2)
2987+
2988+
type_keys('<F3>', 'b')
2989+
eq(child.lua_get('_G.m'), 1)
2990+
end
2991+
29732992
T["'mini.nvim' compatibility"] = new_set({
29742993
hooks = {
29752994
pre_case = function()

0 commit comments

Comments
 (0)