Suggestions as you type
addSuggester shows a list of suggestions under the caret. The list appears when the writer types a trigger character at the start of a word: @ for people, # for tags, : for emoji…
this.addSuggester({
id: 'tags',
trigger: '#',
find: (query) =>
this.tags
.filter((tag) => tag.startsWith(query.toLowerCase()))
.map((tag) => ({ label: tag, insert: `#${tag}`, detail: 'tag' })),
})This is how it behaves:
- What
findgets: the text typed after the trigger so far. Bläck Studio callsfindagain as the writer types, after a 60 ms pause. Keep it quick, and prepare whatever it searches beforehand.findmay be async. If its answer arrives after the writer has typed more, Bläck Studio drops it. - What it returns: suggestions, each with a
label, an optionaldetailshown beside it, and an optionalinsert. When the writer picks a suggestion, itsinsert(or itslabel, if there is noinsert) replaces the trigger and everything typed after it. - The keys: up and down choose a suggestion, Enter or Tab takes it, and Escape hides the list until the writer moves on.
- Limits: Bläck Studio shows at most 12 suggestions, counting every suggester with the same trigger. A trigger in the middle of a word (
e@mail) offers nothing.
Suggesters work in sandboxed plugins too.