Insert a custom node by replacing current selection ? #4728
Replies: 3 comments
-
You could add a check for the selection where you check if its collapsed. If it's not, then handle the creation of your
|
Beta Was this translation helpful? Give feedback.
-
I had it highlighting to different degrees of success with the above solutions but the critical failure was clearing the element node. I was implementing a redaction element where I wanted it to wrap all text nodes and maintain the styling underneath. I got around doing this by just formatting with highlight. Which isn't ideal, as it'd be nice to have highlight on the lowest level text node, and redactions a level higher. I've not seen any examples of adding an element node that don't change the whole line, I'm not sure how possible this is, I'm certain there's a hacky solution but after many hours and a deadline approaching I'm having to give up. I may continue in my spare time if I get somewhere I'll lyk. I'm not a fan of the lexical docs. If you're storing lexical JSON on your backend and don't have access to things like lexical API's hasFormat, you can use the binary operations on the format number to extract if it's highlighted. This thread has a function that can help with that.. |
Beta Was this translation helpful? Give feedback.
-
You might want to look at the |
Beta Was this translation helpful? Give feedback.
-
I have implemented a new node class
HighlightNode
which extendsElementNode
-With the click of a button in the toolbar I dispatch the
INSERT_HIGHLIGHT_COMMAND
, I would like to replace whatever text content is currently selected with this new HighlightNode class, which wraps the selected TextNode inside itself.This new HighlightNode class, sets the new css font-color and backgroundColor styles for the textContent.
Is it possible to change the selection logic below in the registerCommand to only replace the text that is currently selected ?
Do i need to select specifically for the content between the focus and anchor nodes somehow?
Beta Was this translation helpful? Give feedback.
All reactions