Disable node suppression on backspace input
Hi. I'm using input within custom nodes, and whenever I press backspace to delete a character, it removes the node. I know this is a default behaviour, but I can't find how to disable that. (stopping input event propagation does nothing)
Is there a way to avoid this behavior ?
Hey @FlynnTheInfinite . I had same problem and I stopped propagation of keyUp event.
Let me kno if it helps, if not -you can share the code bit, so I can take a look.
Yes, it worked ! Thanks 😄
I resolved this by adding CTRL key modifier to deletion hotkey. This is in onKeyUp in DiagramWidget.
I resolved this by adding CTRL key modifier to deletion hotkey. This is in onKeyUp in DiagramWidget.
Thanks, it worked!
for example:
<DiagramWidget deleteKeys={[]} />
Can any of you share a code snippet where you are overriding the keyup event?
I am using version 6.0.0
This is how I get it work.
Handle focus event on the form, and set
model.setLocked(true);
Then, in the container of diagram area, handle click event, and
model.setLocked(false);
Currently, I am looking how to prevent node/edge deletion, but still allow drag around node.
@ccapeng react-diagrams has a set of "States", which are¹ a set of handlers for events like creating links, dragging the canvas and dragging nodes.
By default, all diagrams come with DefaultDiagramState, which uses DragDiagramItemsState to handle item dragging, which extends MoveItemsState. The disallowing of moving locked entities is found on these lines.
So, to achieve what you want, you could make your own CustomDiagramState (copy of DefaultDiagramState) and set it to use CustomDragDiagramItemsState, which can override the fireMouseMoved function (or you can make your CustomMoveItemsState, change the implementation and make CustomDragDiagramItemsState to extend it).
You could change the implementation to allow only the moving of nodes:
if (item instanceof BasePositionModel) {
//if (item.isLocked()) {
if (!(item instanceof NodeModel) && item.isLocked()) {
continue;
}
}
Hope this helps.
¹ In my understanding. I would really like documentation on this part, to better understand the concepct and the name choice
This was the first result for my problem and the solution I found isn't here so thought I'd share:
For version 6, there's a demo in the demo gallery that does exactly this. See: here.
how i solved it for input onFocus={() => this.props.node.setLocked(true)} onBlur={() => this.props.node.setLocked(false)}