1- local async = require (' java-core.utils.async' )
2- local await = async .wait
1+ local wait = require (' async.waits.wait' )
32local notify = require (' java-core.utils.notify' )
3+ local List = require (' java-core.utils.list' )
44
55local M = {}
66
@@ -11,16 +11,61 @@ local M = {}
1111--- @param format_item ? fun ( item : T ): string
1212--- @return T
1313function M .select (prompt , values , format_item )
14- return await (function (callback )
14+ return wait (function (callback )
1515 vim .ui .select (values , {
1616 prompt = prompt ,
1717 format_item = format_item ,
1818 }, callback )
1919 end )
2020end
2121
22+ function M .multi_select (prompt , values , format_item )
23+ return wait (function (callback )
24+ local wrapped_items = List :new (values ):map (function (item , index )
25+ return {
26+ index = index ,
27+ is_selected = false ,
28+ value = item ,
29+ }
30+ end )
31+
32+ local open_select
33+
34+ open_select = function ()
35+ vim .ui .select (wrapped_items , {
36+ prompt = prompt ,
37+ format_item = function (item )
38+ local prefix = item .is_selected and ' * ' or ' '
39+ return prefix
40+ .. (format_item and format_item (item .value ) or item .value )
41+ end ,
42+ }, function (selected )
43+ if not selected then
44+ local selected_items = wrapped_items
45+ :filter (function (item )
46+ return item .is_selected
47+ end )
48+ :map (function (item )
49+ return item .value
50+ end )
51+
52+ callback (# selected_items > 0 and selected_items or nil )
53+ return
54+ end
55+
56+ wrapped_items [selected .index ].is_selected =
57+ not wrapped_items [selected .index ].is_selected
58+
59+ open_select ()
60+ end )
61+ end
62+
63+ open_select ()
64+ end )
65+ end
66+
2267function M .input (prompt )
23- return await (function (callback )
68+ return wait (function (callback )
2469 vim .ui .input ({
2570 prompt = prompt ,
2671 }, callback )
0 commit comments