Deleting a Nested Node

Hi, I’m trying to implement figures with images and figcaptions (working off initial this thread). A working prototype of that is here.

Based off two previous threads, Defining a container node, that gets removed when empty? and Remove a node if the node is empty on leave, I made a plugin using appendTransactions that removes the entire figure node when the image is deleted.

I do this iterating through the document of the newState and checking if the image src of any figure equals the fault. If so, then I append a deleteRange to a transaction and return that.

The problem is, instead of deleting the entire figure node, it only seems to delete the image node only and reinitialize that image node to default settings.

Update. Not sure why the original link to the prototype on glitch does work but the issue turned out to be a simple error of returning within the iteration of doc.descendants instead of returning the transaction outside of it.