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).