Skip to content

Commit

Permalink
doc: added example with preview
Browse files Browse the repository at this point in the history
  • Loading branch information
desdic committed Dec 4, 2024
1 parent eacba7b commit 45eaa7d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,39 @@ Example using fzf-lua
local results = require("marlin").get_indexes()
local content = {}

require("fzf-lua").fzf_exec(function(fzf_cb)
local fzf_lua = require("fzf-lua")
local builtin = require("fzf-lua.previewer.builtin")
local fzfpreview = builtin.buffer_or_file:extend()

function fzfpreview:new(o, opts, fzf_win)
fzfpreview.super.new(self, o, opts, fzf_win)
setmetatable(self, fzfpreview)
return self
end

function fzfpreview.parse_entry(_, entry_str)
if entry_str == "" then
return {}
end

local entry = content[entry_str]
return {
path = entry.filename,
line = entry.row or 1,
col = 1,
}
end

fzf_lua.fzf_exec(function(fzf_cb)
for i, b in ipairs(results) do
local entry = i .. ":" .. b.filename .. ":" .. b.row .. ":" .. b.col
local entry = i .. ":" .. b.filename .. ":" .. b.row

content[entry] = b
fzf_cb(entry)
end
fzf_cb()
end, {
previewer = fzfpreview,
prompt = "Marlin> ",
actions = {
["ctrl-d"] = {
Expand Down

0 comments on commit 45eaa7d

Please sign in to comment.