Skip to content

preview items#2533

Merged
ibhagwan merged 5 commits into
ibhagwan:mainfrom
phanen:preview_items
Feb 2, 2026
Merged

preview items#2533
ibhagwan merged 5 commits into
ibhagwan:mainfrom
phanen:preview_items

Conversation

@phanen
Copy link
Copy Markdown
Collaborator

@phanen phanen commented Jan 24, 2026

  • feat(previewer): parse_entry can give async preview result
  • feat(ui_select): opts.preview_items

opts.preview_items: neovim/neovim#37360

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Jan 24, 2026

require('fzf-lua').register_ui_select()
vim.ui.select(vim.fn.range(10), {
 preview_item = function(entry_str)
   return {
     content = { '## ' .. entry_str },
     line = 1,
     col = 1 + #'## ',
     end_col = 1 + #'## ' + #entry_str,
     filetype = 'markdown',
   }
 end,
}, print)

EDIT:

require("fzf-lua").register_ui_select()
vim.ui.select(vim.fn.range(10), {
	preview_item = function(entry_str)
		return {
			content = { { { "## " }, { entry_str, "IncSearch" } } },
			filetype = "markdown",
		}
	end,
}, print)

@ibhagwan
Copy link
Copy Markdown
Owner

Amazing @phanen, is this ready for merging or you want to play with it some more until I merge?

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Jan 24, 2026

Maybe we can wait upstream to be merged (maybe they can change function signatures, to give more spec about what preview_items should return)

@phanen phanen force-pushed the preview_items branch 2 times, most recently from 7d5cc26 to 7e7d470 Compare January 31, 2026 13:55
@ibhagwan ibhagwan self-assigned this Jan 31, 2026
@ibhagwan
Copy link
Copy Markdown
Owner

7d5cc26 - great idea

@phanen phanen force-pushed the preview_items branch 2 times, most recently from d9ab67d to dacfffc Compare January 31, 2026 14:43
@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Jan 31, 2026

@ibhagwan
Copy link
Copy Markdown
Owner

Do you want this merged or still wanna wait for neovim/neovim#37360?

entry.content can be `(string|fzf-lua.line)[]`
---@alias fzf-lua.line (string|[string,string])[]

The second part is hlgroup

chore: simplify highlight previewer
fix(previewer): update_render_markdown if it's enabled
@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Feb 1, 2026

Ok, I think no problem to merge.

@ibhagwan
Copy link
Copy Markdown
Owner

ibhagwan commented Feb 2, 2026

Ty @phanen, sorry for the delay as traveling, hope to get to it from the airport :)

@ibhagwan ibhagwan merged commit e5804f4 into ibhagwan:main Feb 2, 2026
8 checks passed
@ibhagwan
Copy link
Copy Markdown
Owner

ibhagwan commented Feb 2, 2026

Tysm @phanen

@neo451
Copy link
Copy Markdown

neo451 commented Mar 5, 2026

hi, great to see this proposal already landing in fzf-lua, I am the one who first raised the issue, since I want to simplify all the picker integrations in obsidian.nvim

I am basically wanting to do this:

---@param values string[]|obsidian.PickerEntry[]
---@param opts obsidian.PickerPickOpts|? Options.
M.pick = function(values, opts)
  opts = opts or {}
  local callback = opts.callback or obsidian.api.open_note
  local format_item = opts.format_item or function(entry)
    return tostring(entry.user_data)
  end

  require("fzf-lua.providers.ui_select").ui_select(values, {
    format_item = format_item,
    preview_item = function(entry)
      local buf = vim.api.nvim_create_buf(false, true)
      vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "hi" })
      return {
        buf = buf,
      }
    end,
    prompt = format_prompt(opts.prompt_title),
  }, function(entry)
    if not entry then
      log.info "Aborted"
      return
    end
    callback(entry)
  end)
end

which is in compliance to the updated proposal in the upsteam issue, maybe this was merged earlier then the updated proposal, but in short the updated proposal requires only one field which is the buf, which makes a lot of sense to fill in, my current try in this shape will result in a preview window with the message unable to stat file

just a heads up, maybe we should wait till it gets merged to update accordingly.

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented Mar 6, 2026

Yeah, currently buf is not supported, fzf-lua never post source buffer directly to avoid messup the metainfo of a buffer like "lastused". But this can be implmented, just need to clarify who need to clear the buffer.

@neo451
Copy link
Copy Markdown

neo451 commented May 9, 2026

update, the upstream spec has been merged, @phanen @ibhagwan

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented May 9, 2026

fixed in #2722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants