Hi,
I’m trying to keep track of my decorations and perform some operations for each decoration that is removed.
For doing so, I thought passing an onRemove callback parameter with the native map() function.
Thing is, that the onRemove will be called whenever the boundaries of this node are deleted (while keeping the rest of the node).
I find this untrevial, as the decoration actually remains.
onRemove should be called when a decoration (not a node) is removed by mapping. And yes, for node decorations that happens when the opening token of the node is deleted or replaced.
If you have a case where it’s not behaving that way, please provide a script to reproduce it.
Thanks a lot, @marijn!
So, If I’d like to be notified only when the decoration is completely removed, what would be the recommended approach?
I thought of using inline decorations instead, but for them to be completely aligned with the node I’m trying to decorate, I’'ve set inclusiveEnd:true, inclusiveStart:true, which caused some awkward behavior when trying to get out of this node (e.g. when at the very end of the document).
Alternatively, I thought of managing this bookkeeping myself - e.g., assigning unique IDs to each decoration and scanning for deletions. I think it might be an overkill, though.
@marijn , but as you just mention, if also notifies when opening (or ending) token is removed while the rest of the decoration is not.
I’m trying to understand how to be notified only when the decoration is removed completely.
I’d like to have a decoration that precisely describes the position of some inline nodes.
Here, an inline decoration is added, aming to wrap an inline node.
Now, I’ve set the selection to include the beginning of the inline node, which includes some of the text before, and then replaced it with new text. As a result, the positions of the decoration and the node no longer match.
You appear to be trying to use decorations for something they aren’t intended for. They store and map view decorations, but tracking nodes is probably best done in another way, such as scanning the document and/or the changed ranges on every transaction.