What I need
Let's start with The mentions plugin taken from the docs.
I would like to enhance if with the following functionality:
- Whenever I click on an existing
MentionNode
, the menu gets rendered (like it does whenmenuRenderFunction
gets called), with the full list of options, regardless of queryString matching - Selecting an option from menu replaces said mention with the newly selected one
Is there a way to implement this while leaving LexicalTypeaheadMenuPlugin
in control of the menu?
Thank you for your time
What I've tried
I figured that maybe I could achieve my desired behaviour simply by returning the right QueryMatch
from triggerFn
. Something like this:
const x: FC = () => {
const nodeAtSelection = useNodeAtSelection() // Returns LexicalNode at selection
return (
<LexicalTypeaheadMenuPlugin<VariableTypeaheadOption>
triggerFn={(text, editor) => {
if ($isMentionsNode(nodeAtSelection)) {
// No idea how to implement `getQueryMatchForMentionsNode`,
// or whether it's even possible
return getQueryMatchForMentionsNode(nodeAtSelection, text, editor)
}
return checkForVariableBeforeCaret(text, editor)
}}
/>
)
}
I played around with it for about half an hour, unfortunately I couldn't really find any documentation for triggerFn
or QueryMatch
, and haven't really made any progress just by messing around.
I also thought of a potential solution the I think would work, but feels very hacky and I would prefer not to use it. I'll post it as an answer.