Keyboard delete not working even after enabling allowDelete

Hi Team,

I have enabled allowDelete in config.

  1. selecting a node and deleting it is not deleting the node. But if I click on node twice and then press keyboard delete, then node is getting deleted. Are we missing something ?

  2. In some cases, even after multiple clicks on node and then press keyboard delete, node is not getting deleted.

The default value for Diagram.allowDelete is true, so you don’t need to set it to allow users to delete a Part.

I cannot explain why it sometimes works and sometimes not. Do you set Diagram.isReadOnly or Part.deletable at all? How do you modify the model, if at all? Have you overridden the CommandHandler.deleteSelection command method? Have you overridden any other methods?

Thanks @walter . Upon configuring properly, I am able to delete using keyboard delete.

But now we are seeing issue consistently that. Only upon clicking on node twice only we are able to delete… If we click on node only once and press delete, it’s not deleting…

We have custom SelectionChanged event handler. But we didn’t override any logic related to delete…

Does your “ChangedSelection” listener change what is selected? It must not do so, else there may be undefined behavior and confusion.

We are not changing selected node as part of ChangedSelection listener @walter

On clicking on orphan node the selected adornment is visible. But delete is not working. Once we click two times on a node and then keyboard delete is working.

OK, you’ll need to investigate why it’s not working in your app.

Pressing the Delete key calls the CommandHandler.deleteSelection method, which performs a transaction in which it calls Diagram.removeParts. You could try setting a breakpoint in those two methods to see if they are called when the user tries to delete the first time.

Depending on what you discover, maybe we can investigate further.

The debugger is not coming into CommandHandler.deleteSelection method for the first delete key click. It’s coming after second click on delete @walter

OK, so now you know that the first Delete key press event is not getting to the Diagram. Normally that is because the Diagram’s Div element does not have keyboard focus.

We know that you have a problem with your Diagram losing focus from your other forum topic.

Hi @walter I tried adding focus explicitly in handleSelectionChanged method

diagram.focus();

It worked for the deletion of nodes. But, it has to work similarly for the undo/redo action right? It’s not happening. Any suggestions here?

We know that there is a problem with focus in your app. Let’s continue in the other forum topic where we are discussing that.