Skip to content

Commit 157521c

Browse files
committed
BUGFIX: Reverse items added to clipboard if they are selected from bottom to top
Relates: #3040
1 parent 445e275 commit 157521c

File tree

1 file changed

+13
-2
lines changed
  • packages/neos-ui-redux-store/src/CR/Nodes

1 file changed

+13
-2
lines changed

packages/neos-ui-redux-store/src/CR/Nodes/helpers.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ export const calculateNewFocusedNodes = (selectionMode: SelectionModeTypes, cont
6767
const lastSelectedNode = nodesByContextPath[lastSelectedNodeContextPath];
6868
if (lastSelectedNode && lastSelectedNode.parent) {
6969
const parentNode = getNodeOrThrow(nodesByContextPath, lastSelectedNode.parent);
70-
const tempSelection: string[] = [];
70+
let tempSelection: string[] = [];
7171
let startSelectionFlag = false;
72+
let startIndex = -1;
73+
let endIndex = -1;
7274
// if both start and end nodes are within children, then we can do range select
73-
const startAndEndOfSelectionAreOnOneLevel = parentNode.children.some(child => {
75+
const startAndEndOfSelectionAreOnOneLevel = parentNode.children.some((child, index) => {
7476
if (child.contextPath === lastSelectedNodeContextPath || child.contextPath === contextPath) {
77+
if (child.contextPath === lastSelectedNodeContextPath) {
78+
startIndex = index;
79+
} else if (child.contextPath === contextPath) {
80+
endIndex = index;
81+
}
7582
if (startSelectionFlag) { // if matches for the second time it means that both start and end of selection were found
7683
tempSelection.push(child.contextPath); // also push the last node
7784
return true;
@@ -84,6 +91,10 @@ export const calculateNewFocusedNodes = (selectionMode: SelectionModeTypes, cont
8491
return false;
8592
});
8693
if (startAndEndOfSelectionAreOnOneLevel) {
94+
// Reverse the selection if the nodes were selected from "bottom" to "top" in the tree, or they would be out of order on insertion
95+
if (startIndex > endIndex) {
96+
tempSelection = tempSelection.reverse();
97+
}
8798
const focusedNodesContextPathsSet = new Set(focusedNodesContextPaths);
8899
tempSelection.forEach(contextPath => focusedNodesContextPathsSet.add(contextPath));
89100
return [...focusedNodesContextPathsSet] as string[];

0 commit comments

Comments
 (0)