diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index e244dd7e9..f5e386916 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -959,6 +959,11 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str) -- kill previously running jobs self:_stop_preview_job() + if entry._scratch_buf then + self:set_preview_buf(entry._scratch_buf) + self:preview_buf_post(entry) + return + end -- check if cached is update-to-date to be reuse local cached, stale = self.bcache:check(entry) entry.cached = cached diff --git a/lua/fzf-lua/providers/ui_select.lua b/lua/fzf-lua/providers/ui_select.lua index 4374fb92b..92b4352a7 100644 --- a/lua/fzf-lua/providers/ui_select.lua +++ b/lua/fzf-lua/providers/ui_select.lua @@ -181,7 +181,17 @@ M.ui_select = function(items, ui_opts, on_choice) _ctor = function() local previewer = require("fzf-lua.previewer.builtin").buffer_or_file:extend() ---@diagnostic disable-next-line: unused - function previewer:parse_entry(entry_str, cb) return ui_opts.preview_item(entry_str, cb) end + function previewer:parse_entry(entry_str, cb) + local res = assert(ui_opts.preview_item(entry_str, cb)) + local pos_start, pos_end = res.pos, res.pos_end + return { + _scratch_buf = res.buf, + line = pos_start and pos_start[1] or 1, + col = pos_start and pos_start[2] or 1, + end_line = pos_end and pos_end[1] or 1, + end_col = pos_end and pos_end[2] or 1, + } + end return previewer end diff --git a/lua/fzf-lua/types.lua b/lua/fzf-lua/types.lua index 4393e3949..2cafedddf 100644 --- a/lua/fzf-lua/types.lua +++ b/lua/fzf-lua/types.lua @@ -39,6 +39,7 @@ local FzfLua = require("fzf-lua") ---@field end_col? integer 1-based ---@field open_term? boolean open_term for content (cmd always open_term) ---@field cache_key? any unique cache key for entry (to reuse preview buffer) +---@field _scratch_buf? integer "unmanaged" buffer ---@class fzf-lua.keymap.Entry: fzf-lua.buffer_or_file.Entry ---@field vmap string?