File’s Link Picker
Alt-f here we go
Realization
first def a global func getFileLinks()
function getFileLinks()
return query[[
from index.tag "link"
where _.toFile
select{
ref = _.ref,
snippet = _.snippet,
page = _.page,
pos = _.pos,
}
order by _.page, _.pos
]]
end
then create the File Link Picker
function navigateToPos(ref, pos)
if ref then
editor.navigate(ref)
if pos then
editor.moveCursor(tonumber(pos), true)
end
return true
end
return false
end
command.define {
name = "Navigate: File Link Picker",
key = "Alt-f",
priority = 1,
run = function()
local tables = getFileLinks()
if not tables or #tables == 0 then
editor.flashNotification("No File Links found.")
return
end
local items = {}
for _, r in ipairs(tables) do
table.insert(items, {
name = r.snippet,
description = string.format("%s @ %d", r.page, r.pos),
ref = r.ref,
page = r.page,
pos = r.pos
})
end
local sel = editor.filterBox("🔍 Select", items, "Choose a File Link...", "a File Link to GoTo")
if not sel then return end
if not navigateToPos(sel.ref, sel.pos) then
editor.flashNotification("Failed to navigate to selected File Link.")
end
end
}
