-
I'm trying to implement a custom toolbar button that replaces the selected text in the editor with a modified version, returned from an async API call. The flow I want is:
The button is added through toolbarPlugin({ toolbarContents }). Here's a simplified version of the button code I tried:
This doesn’t work properly because editorRef.current?.editor seems to be internal and not part of the public MDXEditorMethods API, so TypeScript complains, and sometimes the runtime does too. I also tried using LexicalComposerContext in the toolbar plugin, but that caused the "cannot find a LexicalComposerContext" error — presumably because toolbarContents is rendered outside of the Lexical context. I also tried using a custom Lexical command and dispatching it from the button, registering it inside the MDXEditorComponent, but still couldn’t get it to work as expected. Any guidance or examples would be greatly appreciated! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can grab the current Lexical editor through the Gurx hooks. This will return the root editor (usually), or the nested ones, in case you're using nested editors. You can also use const activeEditor = useCellValue(activeEditor$) |
Beta Was this translation helpful? Give feedback.
You can grab the current Lexical editor through the Gurx hooks. This will return the root editor (usually), or the nested ones, in case you're using nested editors. You can also use
rootEditor$
. All of those are exported from the package.