257
257
258
258
-- conditionally update the context if fzf-lua
259
259
-- interface isn't open
260
- M .CTX = function (includeBuflist )
260
+ M .CTX = function (opts )
261
+ opts = opts or {}
261
262
-- save caller win/buf context, ignore when fzf
262
263
-- is already open (actions.sym_lsym|grep_lgrep)
263
264
local winobj = utils .fzf_winobj ()
@@ -271,10 +272,12 @@ M.CTX = function(includeBuflist)
271
272
-- not to resume or a different picker, i.e. hide files and open buffers
272
273
or winobj and winobj :hidden ()
273
274
then
275
+ -- custom bufnr from caller? (#1757)
276
+ local bufnr = tonumber (opts .buf ) or tonumber (opts .bufnr ) or vim .api .nvim_get_current_buf ()
274
277
M .__CTX = {
275
278
mode = vim .api .nvim_get_mode ().mode ,
276
- bufnr = vim . api . nvim_get_current_buf () ,
277
- bname = vim .api .nvim_buf_get_name (0 ),
279
+ bufnr = bufnr ,
280
+ bname = vim .api .nvim_buf_get_name (bufnr ),
278
281
winid = vim .api .nvim_get_current_win (),
279
282
alt_bufnr = vim .fn .bufnr (" #" ),
280
283
tabnr = vim .fn .tabpagenr (),
@@ -294,7 +297,7 @@ M.CTX = function(includeBuflist)
294
297
-- perhaps a min impact optimization but since only
295
298
-- buffers/tabs use these we only include the current
296
299
-- list of buffers when requested
297
- if includeBuflist and not M .__CTX .buflist then
300
+ if opts . includeBuflist and not M .__CTX .buflist then
298
301
-- also add a map for faster lookups than `utils.tbl_contains`
299
302
-- TODO: is it really faster since we must use string keys?
300
303
M .__CTX .bufmap = {}
@@ -353,7 +356,7 @@ M.fzf = function(contents, opts)
353
356
end
354
357
-- update context and save a copy in options (for actions)
355
358
-- call before creating the window or fzf_winobj is not nil
356
- opts .__CTX = M .CTX ()
359
+ opts .__CTX = M .CTX (opts . ctx )
357
360
if opts .fn_pre_win then
358
361
opts .fn_pre_win (opts )
359
362
end
0 commit comments