@@ -145,6 +145,65 @@ local function fzf_actions(on_select, allow_multi, refocus_status)
145
145
}
146
146
end
147
147
148
+ --- Convert entries to snack picker items
149
+ --- @param entries any[]
150
+ --- @return any[]
151
+ local function entries_to_snack_items (entries )
152
+ local items = {}
153
+ for idx , entry in ipairs (entries ) do
154
+ table.insert (items , { idx = idx , score = 0 , text = entry })
155
+ end
156
+ return items
157
+ end
158
+
159
+ --- Utility function to map actions
160
+ --- @param on_select fun ( item : any | nil )
161
+ --- @param allow_multi boolean
162
+ --- @param refocus_status boolean
163
+ local function snacks_actions (on_select , allow_multi , refocus_status )
164
+ local function refresh (picker )
165
+ picker :close ()
166
+ if refocus_status then
167
+ refocus_status_buffer ()
168
+ end
169
+ end
170
+
171
+ local function confirm (picker , item )
172
+ local selection = {}
173
+ local picker_selected = picker :selected { fallback = true }
174
+
175
+ if # picker_selected > 1 then
176
+ for _ , item in ipairs (picker_selected ) do
177
+ table.insert (selection , item .text )
178
+ end
179
+ else
180
+ local entry = item .text
181
+ local prompt = picker :filter ().pattern
182
+
183
+ local navigate_up_level = entry == " .." and # prompt > 0
184
+ local input_git_refspec = prompt :match (" %^" )
185
+ or prompt :match (" ~" )
186
+ or prompt :match (" @" )
187
+ or prompt :match (" :" )
188
+
189
+ table.insert (selection , (navigate_up_level or input_git_refspec ) and prompt or entry )
190
+ end
191
+
192
+ if selection and selection [1 ] and selection [1 ] ~= " " then
193
+ on_select (allow_multi and selection or selection [1 ])
194
+ end
195
+
196
+ refresh (picker )
197
+ end
198
+
199
+ local function close (picker )
200
+ on_select (nil )
201
+ refresh (picker )
202
+ end
203
+
204
+ return { confirm = confirm , close = close }
205
+ end
206
+
148
207
--- Utility function to map finder opts to fzf
149
208
--- @param opts FinderOpts
150
209
--- @return table
@@ -274,6 +333,21 @@ function Finder:find(on_select)
274
333
elseif config .check_integration (" mini_pick" ) then
275
334
local mini_pick = require (" mini.pick" )
276
335
mini_pick .start { source = { items = self .entries , choose = on_select } }
336
+ elseif config .check_integration (" snacks" ) then
337
+ local snacks_picker = require (" snacks.picker" )
338
+ snacks_picker .pick (nil , {
339
+ title = " Neogit" ,
340
+ prompt = string.format (" %s > " , self .opts .prompt_prefix ),
341
+ items = entries_to_snack_items (self .entries ),
342
+ format = " text" ,
343
+ layout = {
344
+ preset = self .opts .theme ,
345
+ preview = self .opts .previewer ,
346
+ height = self .opts .layout_config .height ,
347
+ border = self .opts .border and " rounded" or " none" ,
348
+ },
349
+ actions = snacks_actions (on_select , self .opts .allow_multi , self .opts .refocus_status ),
350
+ })
277
351
else
278
352
vim .ui .select (self .entries , {
279
353
prompt = string.format (" %s: " , self .opts .prompt_prefix ),
0 commit comments