Skip to content

Commit a8f7d50

Browse files
committed
feat(ivy): swiper-like previewer
can only supported where the previewer is the current buffer works with blines, grep_curbuf, git_blame, treesitter, lsp_document_symbols
1 parent dfd7e1b commit a8f7d50

33 files changed

Lines changed: 449 additions & 295 deletions

File tree

lua/fzf-lua/core.lua

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ M.fzf_resume = function(opts)
228228
return
229229
end
230230
opts = utils.tbl_deep_extend("force", config.__resume_data.opts, opts or {})
231+
utils.set_info(opts.__INFO) -- restore original picker info
231232
assert(opts == config.__resume_data.opts)
232233
opts.cwd = opts.cwd and libuv.expand(opts.cwd) or nil
233234
M.fzf_wrap(config.__resume_data.contents, config.__resume_data.opts)
@@ -329,30 +330,9 @@ M.fzf = function(contents, opts)
329330
if previewer then
330331
-- Attach the previewer to the windows
331332
fzf_win:attach_previewer(previewer)
332-
-- Set the preview command line
333-
opts.preview = previewer:cmdline()
334-
-- fzf 0.40 added 'zero' event for when there's no match
335-
-- clears the preview when there are no matching entries
336-
if utils.has(opts, "fzf", { 0, 40 }) and previewer.zero then
337-
table.insert(opts._fzf_cli_args, "--bind="
338-
.. libuv.shellescape("zero:+" .. previewer:zero()))
339-
end
340-
if type(previewer.preview_window) == "function" then
341-
-- do we need to override the preview_window args?
342-
-- this can happen with the builtin previewer
343-
-- (1) when using a split we use the previewer as placeholder
344-
-- (2) we use 'nohidden:right:0' to trigger preview function
345-
-- calls without displaying the native fzf previewer split
346-
opts.fzf_opts["--preview-window"] = previewer:preview_window()
347-
end
348-
-- provides preview offset when using native previewers
349-
-- (bat/cat/etc) with providers that supply line numbers
350-
-- (grep/quickfix/LSP)
351-
if type(previewer.fzf_delimiter) == "function" then
352-
opts.fzf_opts["--delimiter"] = previewer:fzf_delimiter()
353-
end
354-
if opts.preview_offset == nil and type(previewer._preview_offset) == "function" then
355-
opts.preview_offset = previewer:_preview_offset()
333+
-- Setup --preview/--preview-window/--bind=zero:... etc
334+
if type(previewer.setup_opts) == "function" then
335+
opts = previewer:setup_opts(opts)
356336
end
357337
elseif opts.preview and type(opts.preview) ~= "string" then
358338
opts.preview = require("fzf-lua.previewer").normalize_spec(opts.preview, opts)

lua/fzf-lua/ctx.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local ctx
1616
---@field cursor integer[]
1717
---@field line string
1818
---@field curtab_wins { [string]: boolean }
19+
---@field winopts { winhl: string, cursorline: boolean }
1920
---@field bufmap? { [string]: boolean }
2021
---@field buflist? integer[]
2122

@@ -61,7 +62,11 @@ M.refresh = function(opts)
6162
ret[tostring(w)] = true
6263
end
6364
return ret
64-
end)()
65+
end)(),
66+
winopts = {
67+
winhl = vim.wo.winhl,
68+
cursorline = vim.wo.cursorline,
69+
},
6570
}
6671
end
6772
-- perhaps a min impact optimization but since only

0 commit comments

Comments
 (0)