I am using some Lexial plugin that enhances the copy/paste experience (CopyPasteEnhancementPlugin).
When investigating how it works I found this helper function inside clipboard.ts. The function gets called each time the user pastes some content into Lexical:
export function $insertGeneratedNodes(
editor: LexicalEditor,
nodes: Array<LexicalNode>,
selection: BaseSelection,
): void {
if (
!editor.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
nodes,
selection,
})
) {
selection.insertNodes(nodes);
}
return;
}
I need to intercept the nodes before they get inserted into the selection. E.g. I want to transform the text so all
get replaced with " "
. Or certain words get replaced with some arbitrary text string and so on.
What would be the correct way to do this?