Fixed losing field names on undo/redo moved nodes
This commit is contained in:
parent
f47d17e377
commit
b93ba1106c
|
@ -136,7 +136,8 @@ function History (editor) {
|
||||||
// first copy the nodes, then move them
|
// first copy the nodes, then move them
|
||||||
var nodes = newParentNode.childs.slice(params.newIndex, params.newIndex + params.count);
|
var nodes = newParentNode.childs.slice(params.newIndex, params.newIndex + params.count);
|
||||||
|
|
||||||
nodes.forEach(function (node) {
|
nodes.forEach(function (node, index) {
|
||||||
|
node.field = params.fieldNames[index];
|
||||||
oldParentNode.moveBefore(node, oldBeforeNode);
|
oldParentNode.moveBefore(node, oldBeforeNode);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -149,7 +150,8 @@ function History (editor) {
|
||||||
// first copy the nodes, then move them
|
// first copy the nodes, then move them
|
||||||
var nodes = oldParentNode.childs.slice(params.oldIndex, params.oldIndex + params.count);
|
var nodes = oldParentNode.childs.slice(params.oldIndex, params.oldIndex + params.count);
|
||||||
|
|
||||||
nodes.forEach(function (node) {
|
nodes.forEach(function (node, index) {
|
||||||
|
node.field = params.fieldNames[index];
|
||||||
newParentNode.moveBefore(node, newBeforeNode);
|
newParentNode.moveBefore(node, newBeforeNode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1990,20 +1990,23 @@ Node.onDragEnd = function (nodes, event) {
|
||||||
nodes[0].dom.menu.focus();
|
nodes[0].dom.menu.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
var params = {
|
var oldParentPath = editor.drag.oldParent.getPath();
|
||||||
|
var newParentPath = firstNode.parent.getPath();
|
||||||
|
var oldIndex = editor.drag.oldIndex;
|
||||||
|
var newIndex = firstNode.getIndex();
|
||||||
|
|
||||||
|
if (JSON.stringify(oldParentPath) !== JSON.stringify(newParentPath) || oldIndex !== newIndex) {
|
||||||
|
// only register this action if the node is actually moved to another place
|
||||||
|
editor._onAction('moveNodes', {
|
||||||
count: nodes.length,
|
count: nodes.length,
|
||||||
oldParentPath: editor.drag.oldParent.getPath(),
|
fieldNames: nodes.map(getField),
|
||||||
newParentPath: firstNode.parent.getPath(),
|
oldParentPath: oldParentPath,
|
||||||
oldIndex: editor.drag.oldIndex,
|
newParentPath: newParentPath,
|
||||||
newIndex: firstNode.getIndex(),
|
oldIndex: oldIndex,
|
||||||
|
newIndex: newIndex,
|
||||||
oldSelection: editor.drag.oldSelection,
|
oldSelection: editor.drag.oldSelection,
|
||||||
newSelection: editor.getDomSelection()
|
newSelection: editor.getDomSelection()
|
||||||
};
|
});
|
||||||
|
|
||||||
if (JSON.stringify(params.oldParentPath) !== JSON.stringify(params.newParentPath) ||
|
|
||||||
params.oldIndex !== params.newIndex) {
|
|
||||||
// only register this action if the node is actually moved to another place
|
|
||||||
editor._onAction('moveNodes', params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.style.cursor = editor.drag.oldCursor;
|
document.body.style.cursor = editor.drag.oldCursor;
|
||||||
|
@ -2799,6 +2802,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
count: selectedNodes.length,
|
count: selectedNodes.length,
|
||||||
|
fieldNames: selectedNodes.map(getField),
|
||||||
oldParentPath: oldParent.getPath(),
|
oldParentPath: oldParent.getPath(),
|
||||||
newParentPath: firstNode.parent.getPath(),
|
newParentPath: firstNode.parent.getPath(),
|
||||||
oldIndex: oldIndex,
|
oldIndex: oldIndex,
|
||||||
|
@ -2849,6 +2853,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
count: selectedNodes.length,
|
count: selectedNodes.length,
|
||||||
|
fieldNames: selectedNodes.map(getField),
|
||||||
oldParentPath: oldParent.getPath(),
|
oldParentPath: oldParent.getPath(),
|
||||||
newParentPath: firstNode.parent.getPath(),
|
newParentPath: firstNode.parent.getPath(),
|
||||||
oldIndex: oldIndex,
|
oldIndex: oldIndex,
|
||||||
|
@ -2886,6 +2891,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
count: selectedNodes.length,
|
count: selectedNodes.length,
|
||||||
|
fieldNames: selectedNodes.map(getField),
|
||||||
oldParentPath: oldParent.getPath(),
|
oldParentPath: oldParent.getPath(),
|
||||||
newParentPath: firstNode.parent.getPath(),
|
newParentPath: firstNode.parent.getPath(),
|
||||||
oldIndex: oldIndex,
|
oldIndex: oldIndex,
|
||||||
|
@ -2952,6 +2958,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
count: selectedNodes.length,
|
count: selectedNodes.length,
|
||||||
|
fieldNames: selectedNodes.map(getField),
|
||||||
oldParentPath: oldParent.getPath(),
|
oldParentPath: oldParent.getPath(),
|
||||||
newParentPath: firstNode.parent.getPath(),
|
newParentPath: firstNode.parent.getPath(),
|
||||||
oldIndex: oldIndex,
|
oldIndex: oldIndex,
|
||||||
|
@ -4060,11 +4067,16 @@ Node.prototype._escapeJSON = function (text) {
|
||||||
return escaped;
|
return escaped;
|
||||||
};
|
};
|
||||||
|
|
||||||
// helper function to the get path of a node
|
// helper function to get the path of a node
|
||||||
function getPath (node) {
|
function getPath (node) {
|
||||||
return node.getPath();
|
return node.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper function to get the field of a node
|
||||||
|
function getField (node) {
|
||||||
|
return node.getField();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
|
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
|
||||||
// idea: introduce properties .isAppendNode and .isNode and use that instead of instanceof AppendNode checks
|
// idea: introduce properties .isAppendNode and .isNode and use that instead of instanceof AppendNode checks
|
||||||
var AppendNode = appendNodeFactory(Node);
|
var AppendNode = appendNodeFactory(Node);
|
||||||
|
|
Loading…
Reference in New Issue