Skip to content

Commit 28ed2f0

Browse files
committed
fix(pick): update set_picker_opts to rerun match only if necessary
Related to #2146
1 parent f315665 commit 28ed2f0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lua/mini/pick.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,8 @@ MiniPick.set_picker_opts = function(opts)
17991799
picker.opts = vim.tbl_deep_extend('force', picker.opts, opts or {})
18001800
picker.action_keys = H.normalize_mappings(picker.opts.mappings)
18011801
if cur_cwd ~= picker.opts.source.cwd then H.win_set_cwd(picker.windows.main, picker.opts.source.cwd) end
1802-
H.picker_update(picker, true, true)
1802+
local do_match = ((opts or {}).source or {}).match ~= nil
1803+
H.picker_update(picker, do_match, true)
18031804
end
18041805

18051806
--- Set target window for active picker

tests/screenshots/tests-test_pick.lua---set_picker_opts()---works-003

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
11|~ │ │
1313
12|~ │ │
1414
13|~ │ │
15-
14|~ └ My name ──────── 1|1|3 ┘
15+
14|~ └ My other name ── 1|1|3 ┘
1616
15|
1717

1818
--|---------|---------|---------|---------|
@@ -29,5 +29,5 @@
2929
11|1111126666666666666666666666662111111111
3030
12|1111126666666666666666666666662111111111
3131
13|1111126666666666666666666666662111111111
32-
14|1111127777777772222222277777772111111111
32+
14|1111127777777777777772277777772111111111
3333
15|0000000000000000000000000000000000000000

tests/test_pick.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4549,7 +4549,12 @@ T['set_picker_opts()']['works'] = function()
45494549
eq(child.fn.getcwd(0), full_path(test_dir))
45504550
eq(child.fn.getcwd(target_win_id), init_cwd)
45514551

4552-
-- Should rerun match
4552+
-- Should rerun match, but only if necessary
4553+
type_keys('<C-n>')
4554+
eq(get_picker_matches().current_ind, 2)
4555+
child.lua([[MiniPick.set_picker_opts({ source = { name = 'My other name' } })]])
4556+
eq(get_picker_matches().current_ind, 2)
4557+
45534558
child.lua('MiniPick.set_picker_opts({ source = { match = function() return { 2 } end } })')
45544559
eq(get_picker_matches().all_inds, { 2 })
45554560
child.expect_screenshot()

0 commit comments

Comments
 (0)