Howdy! I've been looking into moving my contact management from google contacts into SB so I can link to people inside my notes, but I like how in notion etc you can type @ to get a list of people to autocomplete. I'd love to have that in silverbullet, as opposed to the list of all pages that appears when you type [[. Is this something currently possible?
1 Like
Yes it’s possible using the editor:complete event listener
Here is the complete space-lua which does what you ask for, not perfect but it does the job:
event.listen {
name = "editor:complete",
run = function(e)
local linePrefix = e.data.linePrefix or ""
local pos = e.data.pos or 0
local match = string.match(linePrefix, "@([a-zA-Z0-9_]*)$")
if not match then
return
end
local people = query[[ from p = index.tag("person")]]
local opts = {}
for _, p in ipairs(people) do
local label = (p.FirstName or "") .. " " .. (p.LastName or "")
local completionText = "[[" .. p.ref .. "|" .. label .. "]]"
table.insert(opts, {
label = label,
detail = p.ref,
apply = function()
editor.dispatch({
changes = {
from = pos - string.len(match) - 1,
to = pos,
insert = completionText
}
})
end
})
end
return {
from = pos - string.len(match),
options = opts
}
end
}
- make sure to replace the actual tag of the page, I used "person" above.
- make sure to replace the attributes 'First Name' and 'LastName' in the label to match your attributes to be used as label and alias for the WikiLink
7 Likes
