Skip to content

Commit 4edca44

Browse files
committed
feat(clue): ensure triggers in 'mini.starter', but prefer its updaters
Details: - The fact that 'mini.clue' doesn't work with 'mini.starter' is mostly an implementation detail (they both use buffer-local mappings). This can be overcome by a reasonably straightforward autocommand that ensures 'mini.clue' triggers and restores conflicting 'mini.starter' mappings, but this is not quite beginner friendly. It is more important in MiniMax, as there were couple of issues with 'mini.clue' not working in 'mini.starter' in the first two weeks after Minimax release. Resolve #1739
1 parent e220cd2 commit 4edca44

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ There are following change types:
8181

8282
- Add `gen_clues.square_brackets` to generate clues for `[` and `]` keys. By @TheLeoP, PR #1937.
8383

84+
- Ensure triggers for 'mini.starter' buffers, but not override its query updaters (like for "g" and "z" triggers).
85+
8486
## mini.diff
8587

8688
### Expand

lua/mini/clue.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ H.keys = {
11841184
-- Special filetypes for which to enable triggers. These are common interactive
11851185
-- not listed filetypes. NOTE: no 'minifiles' as `'` trigger conflicts with its
11861186
-- local `'`. Plus it pollutes `g?` content.
1187-
H.ft_to_enable = { help = true, git = true }
1187+
H.ft_to_enable = { help = true, git = true, ministarter = true }
11881188

11891189
-- Timers
11901190
H.timers = {
@@ -1338,7 +1338,11 @@ H.map_trigger = function(buf_id, trigger)
13381338

13391339
-- Compute mapping RHS
13401340
trigger.keys = H.replace_termcodes(trigger.keys)
1341-
local keys_trans = H.keytrans(trigger.keys)
1341+
local lhs = H.keytrans(trigger.keys)
1342+
1343+
local is_ministarter_map = vim.bo[buf_id].filetype == 'ministarter'
1344+
and vim.api.nvim_buf_call(buf_id, function() return vim.fn.maparg(lhs, trigger.mode) ~= '' end)
1345+
if is_ministarter_map then return end
13421346

13431347
local rhs = function()
13441348
-- Don't act if for some reason entered the same trigger during state exec
@@ -1362,11 +1366,11 @@ H.map_trigger = function(buf_id, trigger)
13621366

13631367
-- Use buffer-local mappings and `nowait` to make it a primary source of
13641368
-- keymap execution
1365-
local desc = string.format('Query keys after "%s"', keys_trans)
1369+
local desc = string.format('Query keys after "%s"', lhs)
13661370
local opts = { buffer = buf_id, nowait = true, desc = desc }
13671371

13681372
-- Create mapping. Use translated variant to make it work with <F*> keys.
1369-
vim.keymap.set(trigger.mode, keys_trans, rhs, opts)
1373+
vim.keymap.set(trigger.mode, lhs, rhs, opts)
13701374
end
13711375

13721376
H.unmap_trigger = function(buf_id, trigger)

tests/test_clue.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,19 @@ T['setup()']['ensures valid triggers on selected special buffers'] = function()
360360
validate_trigger('git', buf_id_git)
361361
end
362362

363+
T['setup()']["works with 'mini.starter'"] = function()
364+
child.lua('require("mini.starter").open()')
365+
local triggers = {
366+
{ mode = 'n', keys = '<Space>' },
367+
{ mode = 'n', keys = 'g' },
368+
}
369+
load_module({ triggers = triggers, window = { delay = 0 } })
370+
371+
-- Should not override query updaters (common for "g", "s", "z" triggers)
372+
validate_trigger_keymap('n', '<Space>', 0)
373+
validate_no_trigger_keymap('n', 'g', 0)
374+
end
375+
363376
T['setup()']['respects `vim.b.miniclue_disable`'] = function()
364377
local init_buf_id = child.api.nvim_get_current_buf()
365378
local other_buf_id = child.api.nvim_create_buf(true, false)

0 commit comments

Comments
 (0)