@@ -601,7 +601,6 @@ MiniClue.enable_all_triggers = function()
601601 -- Map only inside valid listed buffers
602602 if vim .fn .buflisted (buf_id ) == 1 then H .map_buf_triggers (buf_id ) end
603603 end
604- H .state .disable_autocmd_triggers = false
605604end
606605
607606--- Enable triggers in buffer
@@ -618,7 +617,6 @@ MiniClue.disable_all_triggers = function()
618617 for _ , buf_id in ipairs (vim .api .nvim_list_bufs ()) do
619618 H .unmap_buf_triggers (buf_id )
620619 end
621- H .state .disable_autocmd_triggers = true
622620end
623621
624622--- Disable triggers in buffer
@@ -672,6 +670,26 @@ MiniClue.set_mapping_desc = function(mode, lhs, desc)
672670 if not ok_set then H .error (vim .inspect (desc ) .. ' is not a valid description.' ) end
673671end
674672
673+ MiniClue .start_query_process = function (trigger )
674+ -- Don't act if for some reason entered another trigger is already active
675+ local is_in_exec = type (H .exec_trigger ) == ' table'
676+ and H .exec_trigger .mode == trigger .mode
677+ and H .exec_trigger .keys == trigger .keys
678+ if is_in_exec then
679+ H .exec_trigger = nil
680+ return
681+ end
682+
683+ -- Start user query
684+ H .state_set (trigger , { trigger .keys })
685+
686+ -- Do not advance if no other clues to query. NOTE: it is `<= 1` and not
687+ -- `<= 0` because the "init query" mapping should match.
688+ if vim .tbl_count (H .state .clues ) <= 1 then return H .state_exec () end
689+
690+ H .state_advance ()
691+ end
692+
675693--- Generate pre-configured clues
676694---
677695--- This is a table with function elements. Call to actually get array of clues.
@@ -1192,10 +1210,6 @@ H.create_autocommands = function(config)
11921210 au (' RecordingLeave' , ' *' , MiniClue .enable_all_triggers , ' Enable all triggers' )
11931211
11941212 au (' VimResized' , ' *' , H .window_update , ' Update window on resize' )
1195-
1196- if vim .fn .has (' nvim-0.10' ) == 1 then
1197- au (' ModeChanged' , ' n:no' , function () H .start_query ({ mode = " o" , keys = " " }) end , ' Trigger on change to operator-pending mode' )
1198- end
11991213end
12001214
12011215-- stylua: ignore
@@ -1235,31 +1249,6 @@ H.get_buf_var = function(buf_id, name)
12351249end
12361250
12371251-- Triggers -------------------------------------------------------------------
1238- H .start_query = function (trigger )
1239- if vim .fn .has (' nvim-0.10' ) == 1 and vim .fn .state (' m' ) ~= ' ' then
1240- return
1241- end
1242-
1243- if H .state .disable_autocmd_triggers then
1244- return
1245- end
1246-
1247- -- Don't act if for some reason entered another trigger is already active
1248- local is_in_exec = type (H .exec_trigger ) == ' table'
1249- if is_in_exec then
1250- return
1251- end
1252-
1253- -- Start user query
1254- H .state_set (trigger , { trigger .keys })
1255-
1256- -- Do not advance if no other clues to query. NOTE: it is `<= 1` and not
1257- -- `<= 0` because the "init query" mapping should match.
1258- if vim .tbl_count (H .state .clues ) <= 1 then return H .state_exec () end
1259-
1260- H .state_advance ()
1261- end
1262-
12631252H .map_buf_triggers = function (buf_id )
12641253 if not H .is_valid_buf (buf_id ) or H .is_disabled (buf_id ) then return end
12651254
@@ -1277,7 +1266,7 @@ H.unmap_buf_triggers = function(buf_id)
12771266end
12781267
12791268H .map_trigger = function (buf_id , trigger )
1280- if not H .is_valid_buf (buf_id ) then return end
1269+ if not H .is_valid_buf (buf_id ) or trigger . keys == ' ' then return end
12811270
12821271 -- Compute mapping RHS
12831272 trigger .keys = H .replace_termcodes (trigger .keys )
@@ -1289,11 +1278,11 @@ H.map_trigger = function(buf_id, trigger)
12891278 local opts = { buffer = buf_id , nowait = true , desc = desc }
12901279
12911280 -- Create mapping. Use translated variant to make it work with <F*> keys.
1292- vim .keymap .set (trigger .mode , keys_trans , function () H . start_query (trigger ) end , opts )
1281+ vim .keymap .set (trigger .mode , keys_trans , function () MiniClue . start_query_process (trigger ) end , opts )
12931282end
12941283
12951284H .unmap_trigger = function (buf_id , trigger )
1296- if not H .is_valid_buf (buf_id ) then return end
1285+ if not H .is_valid_buf (buf_id ) or trigger . keys == ' ' then return end
12971286
12981287 trigger .keys = H .replace_termcodes (trigger .keys )
12991288
@@ -1383,20 +1372,20 @@ H.state_exec = function()
13831372 local has_postkeys = (clue or {}).postkeys ~= nil
13841373 H .state_reset (has_postkeys )
13851374
1386- -- Disable triggers !!!VERY IMPORTANT!!!
1375+ -- Disable trigger !!!VERY IMPORTANT!!!
13871376 -- This is a workaround against infinite recursion (like if `g` is trigger
13881377 -- then typing `gg`/`g~` would introduce infinite recursion).
13891378 local buf_id = vim .api .nvim_get_current_buf ()
1390- MiniClue . disable_all_triggers ( )
1379+ H . unmap_trigger ( buf_id , trigger )
13911380
13921381 -- Execute keys. The `i` flag is used to fully support Operator-pending mode.
13931382 -- Flag `t` imitates keys as if user typed, which is reasonable but has small
13941383 -- downside with edge cases of 'langmap' (like ':\;;\;:') as it "inverts" key
13951384 -- meaning second time (at least in Normal mode).
13961385 vim .api .nvim_feedkeys (keys_to_type , ' mit' , false )
13971386
1398- -- Enable triggers back after it can no longer harm
1399- vim .schedule (function () MiniClue . enable_all_triggers ( ) end )
1387+ -- Enable trigger back after it can no longer harm
1388+ vim .schedule (function () H . map_trigger ( buf_id , trigger ) end )
14001389
14011390 -- Apply postkeys (in scheduled fashion)
14021391 if has_postkeys then H .state_apply_postkeys (clue .postkeys ) end
@@ -1450,7 +1439,7 @@ H.compute_exec_keys = function()
14501439 -- Normal/Insert mode so extra work should be done to rebuild all keys
14511440 if vim .startswith (cur_mode , ' no' ) then
14521441 res = H .get_forced_submode () .. res
1453- if H .state .trigger .keys ~= " " then
1442+ if H .state .trigger .keys ~= ' ' then
14541443 local operator_tweak = H .operator_tweaks [vim .v .operator ] or function (x ) return x end
14551444 res = operator_tweak (vim .v .operator .. res )
14561445 end
0 commit comments