Ctrl-z undo question

Hi,

How does one handle a node, when the user hits ctrl-z? Is there a function with something like "oneditundo"? My current problem is that my node gets in a bad state, if it is configured, and then undo-ed afterwards with ctrl-z.

1 Like

Hi,

no, there is no undo event like that. Can you expand a bit on how that causes your node to get into a bad state? The undo of an edit event returns a node to its exact configuration prior to the edit.

My node gets information from a GET command via the "oneditprepare" function.
Hereafter one can configure the node. When the "save" button is pushed, the node sends a POST command with the new settings. Now if I hit ctrl-z the HTTP req/res does not get updated (it does not know that there was an undo action).

Hi Simon (@Simo219h),

Interesting question, but I think you have to redesign it somehow.

This is how Node-RED works:

image

  1. You have some node in your server-side flow (which contains a variable A with value 'X').
  2. This node is transferred to your flow editor.
  3. When you open the node's config screen, the oneditprepare is executed. That is the place to fill your config screen, based on the node variables. For example let's say the checkbox should be checked when the value of variable A is 'X'.
  4. The config screen shows the checkbox, and you can unselect it.
  5. When you leave the config screen via the 'Done' button, the oneditsave is called. That allows you to store values from the config screen in the node. Since the checkbox is unchecked now, we will store value 'Y' into variable A. Remark: when you press the 'Cancel' button, the oneditcancel is executed.
  6. When 'everything' (i.e. the entire configuration of all nodes is your flow) is correct, you press the 'Deploy' button. Then the new value 'Y' is stored in variable A of your node on the server.
  7. And when the user does CTRL-Z in between, the old node status is restored. Which means variable A gets again its original value 'X' (instead of Y).

So the oneditsave is not really saving like you save a document in another application. Your are still dealing with temporary data, until the 'Deploy' is triggered. I 'think' it is not good practice to use the the oneditsave to do things on your server, which need to be reverted in case you do CTRLZ. Normally you should do such things as soon as your new value 'Y' arrives on the server. When you executed CTRL-Z afterwards and deploy the original value 'X' again to the server, that is the point where your server side code should revert the things you have done earlier ...

BTW don't think a new feature like oneditundo would make sense, because at that point you don't have your config screen open anymore. And all those functions (oneditprepare, oneditsave, ...) are part of the config screen...

1 Like

I'd like to vote for some kind of UNDO event for the following reason that I have encountered:

  1. Node shows a label based on some internal state
  2. Go and edit that Node changing its state to something shorter than before
  3. Finish editing - the flow reflects the new label and resizes the node to fit it
  4. UNDO in your flow ... your label changes back to a longer one but the node does NOT resize properly to fit it - bug in node-red I suppose
  5. My Node's state is used by another linked node to show its own label, when I save my Node, I set the other node's .dirty and .resize properties and its size and label gets correctly refreshed in the flow.
  6. Do an UNDO and ... voila, nothing changes in the related node, not even the label ...
    So I'd like to be able to "intercept" the undo action so that I can properly restore any related node's label, size as well as my own size...

Unless you can do all this automatically, which would be very nice - you'd need to watch for any property changes in other nodes when one is edited/saved and restore them as part of the same "transaction" + make sure that resizing happens on all updated nodes.