I’m implementing images with upload placeholders, similar to the image upload example. However, I’m using block nodes (instead of inline) for images, and node decorations (instead of widgets) to track placeholders. The intent is to allow editing (e.g. caption) of an image node while the file is uploading. Thus, the node is added to the document immediately, rather than after upload.
Once the upload is complete, I replace the image node’s src attribute with the URL of the uploaded file. However, I’d like to prevent this transaction from being added to the history; src replacement should be transparent to the user and should not be undoable. I’m using
tr.setMeta("addToHistory", false) to accomplish this.
I’m wondering, is this a valid approach to prevent attribute replacement from being undone?
I ask because I’ve noticed that undo works as expected in certain circumstances, but not in others. The expected behaviour is that once an image is uploaded and src replaced, undoing will remove the image node. However, the image node is not removed when undoing in certain circumstances.
I’ve created a basic example that exhibits the behaviour here:
(Note: In reality, I’m using a plugin with node decorations to track placeholders. However, that isn’t pertinent to reproducing the behaviour).
[Working] Place cursor in MIDDLE of any paragraph. Click “Insert image” button. Once image is “uploaded”, perform undo. See that image node is removed as expected.
[Not working] Place cursor at END of any paragraph. Click “Insert image” button. Once image is “uploaded”, perform undo. See that image node is NOT removed.