How can i save a text from being deleted?

hello , i have a DOM element like this

xx< span>[</ span> x< em>x</ em >x <span >]</ span >xxx

how i can keep’[’ and ']‘from being deleted by pressing backspace ? (’['and ‘]’ are in different lines) .

i used handleKeyDown to stop it being deleted, but when i select some text first then pressed backspace, it didn’t work .

i tried dispatchTransaction, but i have no idea how to judge whether there is a ‘[’ ‘]’ or not and after preventing ‘[’ text from being deleted ,the cursor must go 1 character forward and leaving ']'after it . i guess setSelection can help .but …

not only i need to prevent ‘[’ ‘]’ from being deleted ,i also need to prevent some lines from being deleted too.

i’m thinking about add a property on prose mirror node…

Any idea about preventing delete? Many thanks in advance!

A plugin with a filterTransaction hook is probably the best way to do this. But in order to figure out whether a given transaction deletes such a node, you’ll need to read a bit more of the docs—this really isn’t a library where you can just poke at the objects you’re given to figure out what to do. You’ll probably want to use nodesBetween with the ranges from the step maps on the transaction to scan whether one of the nodes you want to preserve is in the replaced ranges, and cancel the transaction when that’s the case.

Thank you for the information regarding this topic.

i have read the guide, and successfully stop the backspace working

but when i try to move the cursor 1 character forward, i find the whole node i inserted has only 1 position in the document,

is it not recommended to use Node.create() to create a whole span of text ?

Best regards