react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

Disable node suppression on backspace input

Open FabienMorival opened this issue 8 years ago • 9 comments

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 ?

FabienMorival avatar Aug 07 '18 08:08 FabienMorival

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.

JokerNN avatar Aug 08 '18 12:08 JokerNN

Yes, it worked ! Thanks 😄

FabienMorival avatar Aug 09 '18 11:08 FabienMorival

I resolved this by adding CTRL key modifier to deletion hotkey. This is in onKeyUp in DiagramWidget.

iyobo avatar Sep 05 '18 05:09 iyobo

I resolved this by adding CTRL key modifier to deletion hotkey. This is in onKeyUp in DiagramWidget.

Thanks, it worked!

for example:

<DiagramWidget deleteKeys={[]} />

puckwang avatar Jul 23 '19 07:07 puckwang

Can any of you share a code snippet where you are overriding the keyup event?

I am using version 6.0.0

jestingthomas avatar Nov 19 '19 09:11 jestingthomas

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 avatar Jan 17 '20 09:01 ccapeng

@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

renato-bohler avatar Jan 17 '20 12:01 renato-bohler

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.

noahtren avatar Jan 18 '20 01:01 noahtren

how i solved it for input onFocus={() => this.props.node.setLocked(true)} onBlur={() => this.props.node.setLocked(false)}

d2askif avatar Aug 09 '20 21:08 d2askif