Skip to content

Commit 4438e2d

Browse files
committed
fix(ui_select): align upstream opts.preview_item spec
1 parent 33fe4b6 commit 4438e2d

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

lua/fzf-lua/previewer/builtin.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,9 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
959959
-- kill previously running jobs
960960
self:_stop_preview_job()
961961

962+
if entry._scratch_buf then
963+
return self:_set_preview_lines(entry._scratch_buf, entry)
964+
end
962965
-- check if cached is update-to-date to be reuse
963966
local cached, stale = self.bcache:check(entry)
964967
entry.cached = cached

lua/fzf-lua/providers/ui_select.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ M.ui_select = function(items, ui_opts, on_choice)
181181
_ctor = function()
182182
local previewer = require("fzf-lua.previewer.builtin").buffer_or_file:extend()
183183
---@diagnostic disable-next-line: unused
184-
function previewer:parse_entry(entry_str, cb) return ui_opts.preview_item(entry_str, cb) end
184+
function previewer:parse_entry(entry_str, cb)
185+
local res = ui_opts.preview_item(entry_str, cb)
186+
local pos_start, pos_end = res.pos, res.pos_end
187+
return {
188+
_scratch_buf = res.buf,
189+
line = pos_start and pos_start[1] or 1,
190+
col = pos_start and pos_start[2] or 1,
191+
end_line = pos_end and pos_end[1] or 1,
192+
end_col = pos_end and pos_end[2] or 1,
193+
}
194+
end
185195

186196
return previewer
187197
end

lua/fzf-lua/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ local FzfLua = require("fzf-lua")
3939
---@field end_col? integer 1-based
4040
---@field open_term? boolean open_term for content (cmd always open_term)
4141
---@field cache_key? any unique cache key for entry (to reuse preview buffer)
42+
---@field _scratch_buf? integer "unmanaged" buffer
4243

4344
---@class fzf-lua.keymap.Entry: fzf-lua.buffer_or_file.Entry
4445
---@field vmap string?

0 commit comments

Comments
 (0)