Compare commits

...

3 Commits

Author SHA1 Message Date
Mark Tolmacs 54a123e7c0 Merge branch 'master' into mtolmacs/fix/z-ordering
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2026-06-04 16:37:21 +00:00
Mark Tolmacs fed4af4381 fix: Move to top or bottom
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2026-04-25 16:04:14 +00:00
Mark Tolmacs e97c3704eb fix: Z-orddering with frames
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2026-04-23 19:38:05 +00:00
+21 -38
View File
@@ -409,8 +409,10 @@ const shiftElementsToEnd = (
let trailingIndex: number; let trailingIndex: number;
if (direction === "left") { if (direction === "left") {
if (containingFrame) { if (containingFrame) {
leadingIndex = findIndex(elements, (el) => leadingIndex = findIndex(
isOfTargetFrame(el, containingFrame), elements,
(el) =>
el.id !== containingFrame && isOfTargetFrame(el, containingFrame),
); );
} else if (appState.editingGroupId) { } else if (appState.editingGroupId) {
const groupElements = getElementsInGroup( const groupElements = getElementsInGroup(
@@ -428,8 +430,10 @@ const shiftElementsToEnd = (
trailingIndex = indicesToMove[indicesToMove.length - 1]; trailingIndex = indicesToMove[indicesToMove.length - 1];
} else { } else {
if (containingFrame) { if (containingFrame) {
trailingIndex = findLastIndex(elements, (el) => trailingIndex = findLastIndex(
isOfTargetFrame(el, containingFrame), elements,
(el) =>
el.id !== containingFrame && isOfTargetFrame(el, containingFrame),
); );
} else if (appState.editingGroupId) { } else if (appState.editingGroupId) {
const groupElements = getElementsInGroup( const groupElements = getElementsInGroup(
@@ -499,10 +503,7 @@ function shiftElementsAccountingForFrames(
}), }),
); );
const frameAwareContiguousElementsToMove: { const regularElements: ExcalidrawElement[] = [];
regularElements: ExcalidrawElement[];
frameChildren: Map<ExcalidrawFrameLikeElement["id"], ExcalidrawElement[]>;
} = { regularElements: [], frameChildren: new Map() };
const fullySelectedFrames = new Set<ExcalidrawFrameLikeElement["id"]>(); const fullySelectedFrames = new Set<ExcalidrawFrameLikeElement["id"]>();
@@ -512,51 +513,33 @@ function shiftElementsAccountingForFrames(
} }
} }
const selectedFrameIds = new Set<ExcalidrawFrameLikeElement["id"]>();
for (const element of allElements) { for (const element of allElements) {
if (elementsToMove.has(element.id)) { if (elementsToMove.has(element.id)) {
if ( if (
isFrameLikeElement(element) || isFrameLikeElement(element) ||
(element.frameId && fullySelectedFrames.has(element.frameId)) (element.frameId && fullySelectedFrames.has(element.frameId))
) { ) {
frameAwareContiguousElementsToMove.regularElements.push(element); regularElements.push(element);
} else if (!element.frameId) { } else if (!element.frameId) {
frameAwareContiguousElementsToMove.regularElements.push(element); regularElements.push(element);
} else { } else if (!selectedFrameIds.has(element.frameId)) {
const frameChildren = selectedFrameIds.add(element.frameId);
frameAwareContiguousElementsToMove.frameChildren.get( regularElements.push(element);
element.frameId,
) || [];
frameChildren.push(element);
frameAwareContiguousElementsToMove.frameChildren.set(
element.frameId,
frameChildren,
);
} }
} }
} }
let nextElements = allElements; const containingFrame =
selectedFrameIds.size > 0 ? [...selectedFrameIds][0] : null;
const frameChildrenSets = Array.from(
frameAwareContiguousElementsToMove.frameChildren.entries(),
);
for (const [frameId, children] of frameChildrenSets) {
nextElements = shiftFunction(
allElements,
appState,
direction,
frameId,
children,
);
}
return shiftFunction( return shiftFunction(
nextElements, allElements,
appState, appState,
direction, direction,
null, containingFrame,
frameAwareContiguousElementsToMove.regularElements, regularElements,
); );
} }