Issue with node deletion

Hi, I have a node of type step that contains some text. When the text is empty I am not able to edit it anymore, so I would like to delete the whole Step. the problem is that it seems quite difficult.

let keysHandlerPlugin = new Plugin({
    props: {
        handleKeyDown(view, event) {
            let tr = view.state.tr;
            if (event.keyCode === 8) {
                console.log("CAPTURE BACKSPACE");
                var $from = tr.selection.$from;
                var $to = tr.selection.$from;
                var pos = -1;
                // Here I find the last Node in the path
                for (var i =0;i<$from.path.length;i++) {
                    if ($from.path[i].type !== undefined) {
                        pos = i;
                    }
                }
                if (pos != -1) {
                    let currentNode =  $from.path[pos];                    
                    if (currentNode.type.name == "step" && currentNode.child(0).text.length == 1) {
                        console.log("Will delete");
                        view.dispatch(
                            // Nothing happens :(
                            tr.delete($from.pos, $to.pos)
                        );
                        event.preventDefault();
                        return true;
                    }
                }

            }
            return false;
        },
    },
});

Now, I am using the current selection position and that does not work. I would like to specify the position of the step node containing the text but I have no idea how to find that out. I understand that node has no identity and the position is required for most API but it seems quite difficult to deal with position and nodes. At least, it comes very unnatural to me, coming from different frameworks where nodes have identity (not criticizing the design, just explaining why I am finding that hard to understand).

This is just nonsense. path isn’t part of the ResolvedPos interface, and iterating over it like this is never useful. It looks like you’re computing $from.parent in a really roundabout way. Which is not the node before the position (that’s $from.nodeBefore).

I think reading the docs a bit more closely would be the most fruitful way forward here.

Hi, I am sorry if my question is frustrating. Having maintained several open-source projects I can understand it is frustrating to hear some questions, but I can assure I read the documentation and tried hard before asking the question. I would use $from.parent but then I would not be able to find the position of such parent. This is why I thought I had to look into path.

$from.before() and $from.after() tell you the extent of the parent node. You never need to touch .path.