From 7adf102d8d6d57ea3e5e7217fd959c1f1daf550f Mon Sep 17 00:00:00 2001 From: Kunihiko Toumura Date: Sat, 22 Jun 2019 16:05:50 +0900 Subject: [PATCH] Initial implementation of redo (un-undo) --- .../@node-red/editor-client/src/js/history.js | 164 +++++++++++++++++- .../editor-client/src/js/keymap.json | 6 +- .../@node-red/editor-client/src/js/ui/view.js | 1 + 3 files changed, 167 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/history.js b/packages/node_modules/@node-red/editor-client/src/js/history.js index 930598dd5..b59af14d5 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/history.js +++ b/packages/node_modules/@node-red/editor-client/src/js/history.js @@ -15,6 +15,7 @@ **/ RED.history = (function() { var undo_history = []; + var redo_history = []; function undoEvent(ev) { var i; @@ -22,52 +23,81 @@ RED.history = (function() { var node; var subflow; var modifiedTabs = {}; + var inv_ev; if (ev) { if (ev.t == 'multi') { + inv_ev = { + t: 'multi', + events: [] + }; len = ev.events.length; for (i=len-1;i>=0;i--) { - undoEvent(ev.events[i]); + var r = undoEvent(ev.events[i]); + inv_ev.events.push(r); } } else if (ev.t == 'replace') { + inv_ev = { + t: 'replace', + config: RED.nodes.createCompleteNodeSet(), + changed: [], + rev: RED.nodes.version() + }; RED.nodes.clear(); var imported = RED.nodes.import(ev.config); imported[0].forEach(function(n) { if (ev.changed[n.id]) { n.changed = true; + inv_ev.changed[n.id] = true; } }) RED.nodes.version(ev.rev); } else if (ev.t == 'add') { + inv_ev = { + t: "delete", + }; if (ev.nodes) { + inv_ev.nodes = []; for (i=0;i ev.subflow.inputCount) { + inv_ev.subflow.inputs = ev.node.in.slice(ev.subflow.inputCount); ev.node.in.splice(ev.subflow.inputCount); } else if (ev.subflow.inputs.length > 0) { ev.node.in = ev.node.in.concat(ev.subflow.inputs); } } if (ev.subflow.hasOwnProperty('outputCount')) { + inv_ev.subflow.outputCount = ev.node.out.length; if (ev.node.out.length > ev.subflow.outputCount) { + inv_ev.subflow.outputs = ev.node.out.slice(ev.subflow.outputCount); ev.node.out.splice(ev.subflow.outputCount); } else if (ev.subflow.outputs.length > 0) { ev.node.out = ev.node.out.concat(ev.subflow.outputs); } } if (ev.subflow.hasOwnProperty('instances')) { + inv_ev.subflow.instances = []; ev.subflow.instances.forEach(function(n) { + inv_ev.subflow.instances.push(n); var node = RED.nodes.node(n.id); if (node) { node.changed = n.changed; @@ -258,9 +333,11 @@ RED.history = (function() { var outputMap; if (ev.outputMap) { outputMap = {}; + inv_ev.outputMap = {}; for (var port in ev.outputMap) { if (ev.outputMap.hasOwnProperty(port) && ev.outputMap[port] !== "-1") { outputMap[ev.outputMap[port]] = port; + inv_ev.outputMap[ev.outputMap[port]] = port; } } } @@ -268,39 +345,106 @@ RED.history = (function() { RED.editor.validateNode(ev.node); } if (ev.links) { + inv_ev.createdLinks = []; for (i=0;i