@@ -2,6 +2,7 @@ local uv = vim.uv or vim.loop
22local core = require " fzf-lua.core"
33local path = require " fzf-lua.path"
44local utils = require " fzf-lua.utils"
5+ local libuv = require " fzf-lua.libuv"
56local config = require " fzf-lua.config"
67
78local M = {}
@@ -121,7 +122,7 @@ M.combine = function(t)
121122
122123 local cmds , opts = (function ()
123124 local ret , opts = {}, nil
124- for i , p in ipairs (t .pickers ) do
125+ for _ , p in ipairs (t .pickers ) do
125126 -- local ok, msg, cmd, o = pcall(FzfLua[p], opts1)
126127 -- if not ok or not cmd then
127128 local _ , cmd , o = FzfLua [p ](opts1 )
@@ -148,4 +149,61 @@ M.combine = function(t)
148149 return core .fzf_wrap (contents , opts )
149150end
150151
152+ M .global = function (opts )
153+ opts = config .normalize_opts (opts , " global" )
154+ if not opts then return end
155+
156+ if opts .line_query and not utils .has (opts , " fzf" , { 0 , 59 }) then
157+ utils .warn (" 'global' requires fzf >= 0.59, reverting to files." )
158+ return FzfLua .files (opts )
159+ end
160+
161+ -- Tells fzf_wrap to not start the fzf process
162+ opts ._start = false
163+ local pickers = {
164+ files = { FzfLua .files (vim .deepcopy (opts )) },
165+ buffers = { FzfLua .buffers (vim .deepcopy (opts )) },
166+ lsp_document_symbols = { FzfLua .lsp_document_symbols (vim .deepcopy (opts )) },
167+ lsp_workspace_symbols = { FzfLua .lsp_workspace_symbols (vim .deepcopy (opts )) },
168+ }
169+
170+ -- Remove the `_start` directive from all pickers
171+ opts ._start = nil
172+ for _ , v in pairs (pickers ) do
173+ v [3 ]._start = nil
174+ end
175+
176+ local get_picker = function (q )
177+ q = type (q ) == " string" and q or " "
178+ if q :match (" ^%$" ) then
179+ return pickers .buffers , 2
180+ elseif q :match (" ^@" ) then
181+ return pickers .lsp_document_symbols , 2
182+ elseif q :match (" ^#" ) then
183+ return pickers .lsp_workspace_symbols , 2
184+ else
185+ return pickers .files , 1
186+ end
187+ end
188+
189+ -- Get starting picker
190+ local current_picker = get_picker ()
191+
192+ --- @diagnostic disable-next-line : redefined-local
193+ local contents , opts = current_picker [2 ], current_picker [3 ]
194+
195+ table.insert (opts ._fzf_cli_args , " --bind=" .. libuv .shellescape (" change:+transform:"
196+ .. FzfLua .shell .stringify_data (function (args , _ , _ )
197+ local q = args [1 ]
198+ local new_picker , sub = get_picker (q )
199+ -- Do we need to change the picker?
200+ if current_picker ~= new_picker then
201+ current_picker = new_picker
202+ return string.format (" search(%s)+reload:%s" , q :sub (sub ), new_picker [2 ])
203+ end
204+ end , opts , " {q}" )))
205+
206+ return core .fzf_wrap (contents , opts )
207+ end
208+
151209return M
0 commit comments