Some fixes in keyboard shortcuts to move a multi selection
This commit is contained in:
parent
96c4204b1c
commit
e90248c0d0
|
@ -2006,6 +2006,11 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
var oldBeforeNode;
|
var oldBeforeNode;
|
||||||
var nodes;
|
var nodes;
|
||||||
var multiselection;
|
var multiselection;
|
||||||
|
var selectedNodes = this.editor.multiselection.nodes.length > 0
|
||||||
|
? this.editor.multiselection.nodes
|
||||||
|
: [this];
|
||||||
|
var firstNode = selectedNodes[0];
|
||||||
|
var lastNode = selectedNodes[selectedNodes.length - 1];
|
||||||
|
|
||||||
// util.log(ctrlKey, keynum, event.charCode); // TODO: cleanup
|
// util.log(ctrlKey, keynum, event.charCode); // TODO: cleanup
|
||||||
if (keynum == 13) { // Enter
|
if (keynum == 13) { // Enter
|
||||||
|
@ -2029,10 +2034,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
}
|
}
|
||||||
else if (keynum == 68) { // D
|
else if (keynum == 68) { // D
|
||||||
if (ctrlKey && editable) { // Ctrl+D
|
if (ctrlKey && editable) { // Ctrl+D
|
||||||
nodes = this.editor.multiselection.nodes.length > 0
|
Node.onDuplicate(selectedNodes);
|
||||||
? this.editor.multiselection.nodes
|
|
||||||
: this;
|
|
||||||
Node.onDuplicate(nodes);
|
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2051,10 +2053,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
}
|
}
|
||||||
else if (keynum == 46 && editable) { // Del
|
else if (keynum == 46 && editable) { // Del
|
||||||
if (ctrlKey) { // Ctrl+Del
|
if (ctrlKey) { // Ctrl+Del
|
||||||
nodes = this.editor.multiselection.nodes.length > 0
|
Node.onRemove(selectedNodes);
|
||||||
? this.editor.multiselection.nodes
|
|
||||||
: this;
|
|
||||||
Node.onRemove(nodes);
|
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2071,9 +2070,9 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
else if (keynum == 35) { // End
|
else if (keynum == 35) { // End
|
||||||
if (altKey) { // Alt+End
|
if (altKey) { // Alt+End
|
||||||
// find the last node
|
// find the last node
|
||||||
var lastNode = this._lastNode();
|
var endNode = this._lastNode();
|
||||||
if (lastNode) {
|
if (endNode) {
|
||||||
lastNode.focus(Node.focusElement || this._getElementName(target));
|
endNode.focus(Node.focusElement || this._getElementName(target));
|
||||||
}
|
}
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
@ -2081,9 +2080,9 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
else if (keynum == 36) { // Home
|
else if (keynum == 36) { // Home
|
||||||
if (altKey) { // Alt+Home
|
if (altKey) { // Alt+Home
|
||||||
// find the first node
|
// find the first node
|
||||||
var firstNode = this._firstNode();
|
var homeNode = this._firstNode();
|
||||||
if (firstNode) {
|
if (homeNode) {
|
||||||
firstNode.focus(Node.focusElement || this._getElementName(target));
|
homeNode.focus(Node.focusElement || this._getElementName(target));
|
||||||
}
|
}
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
@ -2098,12 +2097,12 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow left
|
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow left
|
||||||
if (this.expanded) {
|
if (lastNode.expanded) {
|
||||||
var appendDom = this.getAppend();
|
var appendDom = lastNode.getAppend();
|
||||||
nextDom = appendDom ? appendDom.nextSibling : undefined;
|
nextDom = appendDom ? appendDom.nextSibling : undefined;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var dom = this.getDom();
|
var dom = lastNode.getDom();
|
||||||
nextDom = dom.nextSibling;
|
nextDom = dom.nextSibling;
|
||||||
}
|
}
|
||||||
if (nextDom) {
|
if (nextDom) {
|
||||||
|
@ -2111,16 +2110,18 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
nextDom2 = nextDom.nextSibling;
|
nextDom2 = nextDom.nextSibling;
|
||||||
nextNode2 = Node.getNodeFromTarget(nextDom2);
|
nextNode2 = Node.getNodeFromTarget(nextDom2);
|
||||||
if (nextNode && nextNode instanceof AppendNode &&
|
if (nextNode && nextNode instanceof AppendNode &&
|
||||||
!(this.parent.childs.length == 1) &&
|
!(lastNode.parent.childs.length == 1) &&
|
||||||
nextNode2 && nextNode2.parent) {
|
nextNode2 && nextNode2.parent) {
|
||||||
oldSelection = this.editor.getSelection();
|
oldSelection = this.editor.getSelection();
|
||||||
oldBeforeNode = this._nextSibling();
|
oldBeforeNode = lastNode._nextSibling();
|
||||||
|
|
||||||
nextNode2.parent.moveBefore(this, nextNode2);
|
selectedNodes.forEach(function (node) {
|
||||||
|
nextNode2.parent.moveBefore(node, nextNode2);
|
||||||
|
});
|
||||||
this.focus(Node.focusElement || this._getElementName(target));
|
this.focus(Node.focusElement || this._getElementName(target));
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
nodes: [this],
|
nodes: selectedNodes,
|
||||||
oldBeforeNode: oldBeforeNode,
|
oldBeforeNode: oldBeforeNode,
|
||||||
newBeforeNode: nextNode2,
|
newBeforeNode: nextNode2,
|
||||||
oldSelection: oldSelection,
|
oldSelection: oldSelection,
|
||||||
|
@ -2156,16 +2157,18 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
}
|
}
|
||||||
else if (altKey && shiftKey) { // Alt + Shift + Arrow Up
|
else if (altKey && shiftKey) { // Alt + Shift + Arrow Up
|
||||||
// find the previous node
|
// find the previous node
|
||||||
prevNode = this._previousNode();
|
prevNode = firstNode._previousNode();
|
||||||
if (prevNode && prevNode.parent) {
|
if (prevNode && prevNode.parent) {
|
||||||
oldSelection = this.editor.getSelection();
|
oldSelection = this.editor.getSelection();
|
||||||
oldBeforeNode = this._nextSibling();
|
oldBeforeNode = lastNode._nextSibling();
|
||||||
|
|
||||||
prevNode.parent.moveBefore(this, prevNode);
|
selectedNodes.forEach(function (node) {
|
||||||
|
prevNode.parent.moveBefore(node, prevNode);
|
||||||
|
});
|
||||||
this.focus(Node.focusElement || this._getElementName(target));
|
this.focus(Node.focusElement || this._getElementName(target));
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
nodes: [this],
|
nodes: selectedNodes,
|
||||||
oldBeforeNode: oldBeforeNode,
|
oldBeforeNode: oldBeforeNode,
|
||||||
newBeforeNode: prevNode,
|
newBeforeNode: prevNode,
|
||||||
oldSelection: oldSelection,
|
oldSelection: oldSelection,
|
||||||
|
@ -2185,7 +2188,7 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
else if (altKey && shiftKey) { // Alt + Shift + Arrow Right
|
else if (altKey && shiftKey) { // Alt + Shift + Arrow Right
|
||||||
dom = this.getDom();
|
dom = firstNode.getDom();
|
||||||
var prevDom = dom.previousSibling;
|
var prevDom = dom.previousSibling;
|
||||||
if (prevDom) {
|
if (prevDom) {
|
||||||
prevNode = Node.getNodeFromTarget(prevDom);
|
prevNode = Node.getNodeFromTarget(prevDom);
|
||||||
|
@ -2193,13 +2196,15 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
(prevNode instanceof AppendNode)
|
(prevNode instanceof AppendNode)
|
||||||
&& !prevNode.isVisible()) {
|
&& !prevNode.isVisible()) {
|
||||||
oldSelection = this.editor.getSelection();
|
oldSelection = this.editor.getSelection();
|
||||||
oldBeforeNode = this._nextSibling();
|
oldBeforeNode = lastNode._nextSibling();
|
||||||
|
|
||||||
prevNode.parent.moveBefore(this, prevNode);
|
selectedNodes.forEach(function (node) {
|
||||||
|
prevNode.parent.moveBefore(node, prevNode);
|
||||||
|
});
|
||||||
this.focus(Node.focusElement || this._getElementName(target));
|
this.focus(Node.focusElement || this._getElementName(target));
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
nodes: [this],
|
nodes: selectedNodes,
|
||||||
oldBeforeNode: oldBeforeNode,
|
oldBeforeNode: oldBeforeNode,
|
||||||
newBeforeNode: prevNode,
|
newBeforeNode: prevNode,
|
||||||
oldSelection: oldSelection,
|
oldSelection: oldSelection,
|
||||||
|
@ -2235,22 +2240,24 @@ Node.prototype.onKeyDown = function (event) {
|
||||||
}
|
}
|
||||||
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Down
|
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Down
|
||||||
// find the 2nd next node and move before that one
|
// find the 2nd next node and move before that one
|
||||||
if (this.expanded) {
|
if (lastNode.expanded) {
|
||||||
nextNode = this.append ? this.append._nextNode() : undefined;
|
nextNode = lastNode.append ? lastNode.append._nextNode() : undefined;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nextNode = this._nextNode();
|
nextNode = lastNode._nextNode();
|
||||||
}
|
}
|
||||||
var nextNode2 = nextNode && (nextNode._nextNode() || nextNode.parent.append);
|
var nextNode2 = nextNode && (nextNode._nextNode() || nextNode.parent.append);
|
||||||
if (nextNode2 && nextNode2.parent) {
|
if (nextNode2 && nextNode2.parent) {
|
||||||
oldSelection = this.editor.getSelection();
|
oldSelection = this.editor.getSelection();
|
||||||
oldBeforeNode = this._nextSibling();
|
oldBeforeNode = lastNode._nextSibling();
|
||||||
|
|
||||||
nextNode2.parent.moveBefore(this, nextNode2);
|
selectedNodes.forEach(function (node) {
|
||||||
|
nextNode2.parent.moveBefore(node, nextNode2);
|
||||||
|
});
|
||||||
this.focus(Node.focusElement || this._getElementName(target));
|
this.focus(Node.focusElement || this._getElementName(target));
|
||||||
|
|
||||||
this.editor._onAction('moveNodes', {
|
this.editor._onAction('moveNodes', {
|
||||||
nodes: [this],
|
nodes: selectedNodes,
|
||||||
oldBeforeNode: oldBeforeNode,
|
oldBeforeNode: oldBeforeNode,
|
||||||
newBeforeNode: nextNode2,
|
newBeforeNode: nextNode2,
|
||||||
oldSelection: oldSelection,
|
oldSelection: oldSelection,
|
||||||
|
|
Loading…
Reference in New Issue