Skip to content

Commit

Permalink
fix(pick): make set_picker_items() recompute range of shown items
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Dec 27, 2024
1 parent 0b381de commit 9d40696
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/mini/pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,8 @@ H.picker_set_items = function(picker, items, opts)
H.picker_set_busy(picker, false)

H.picker_set_match_inds(picker, H.seq_along(items))
-- Force update visible range for correct "show" lines computation
H.picker_set_current_ind(picker, picker.current_ind, true)
H.picker_update(picker, opts.do_match)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--|---------|---------|---------|---------|
01|
02|~
03|~
04|~
05|┌> ▏─────────────────────┐
06|│c │
07|│d │
08|│e │
09|│ │
10|│ │
11|│ │
12|│ │
13|│ │
14|└ <No name> ────── 1|3|3 ┘
15|

--|---------|---------|---------|---------|
01|0000000000000000000000000000000000000000
02|1111111111111111111111111111111111111111
03|1111111111111111111111111111111111111111
04|1111111111111111111111111111111111111111
05|2333222222222222222222222211111111111111
06|2444444444444444444444444211111111111111
07|2555555555555555555555555211111111111111
08|2555555555555555555555555211111111111111
09|2666666666666666666666666211111111111111
10|2666666666666666666666666211111111111111
11|2666666666666666666666666211111111111111
12|2666666666666666666666666211111111111111
13|2666666666666666666666666211111111111111
14|2777777777772222227777777211111111111111
15|0000000000000000000000000000000000000000
6 changes: 6 additions & 0 deletions tests/test_pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3742,6 +3742,12 @@ T['set_picker_items()']['resets query cache'] = function()
eq(get_picker_matches().all_inds, { 2, 3 })
end

T['set_picker_items()']['recomputes visible range'] = function()
start_with_items({ 'a', 'b' })
set_picker_items({ 'c', 'd', 'e' })
child.expect_screenshot()
end

T['set_picker_items()']['respects `opts.do_match`'] = function()
local validate_match_calls = make_match_with_count()
child.lua_notify([[MiniPick.start({ source = { match = _G.match_with_count } })]])
Expand Down

0 comments on commit 9d40696

Please sign in to comment.