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;
if (direction === "left") {
if (containingFrame) {
leadingIndex = findIndex(elements, (el) =>
isOfTargetFrame(el, containingFrame),
leadingIndex = findIndex(
elements,
(el) =>
el.id !== containingFrame && isOfTargetFrame(el, containingFrame),
);
} else if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
@@ -428,8 +430,10 @@ const shiftElementsToEnd = (
trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (containingFrame) {
trailingIndex = findLastIndex(elements, (el) =>
isOfTargetFrame(el, containingFrame),
trailingIndex = findLastIndex(
elements,
(el) =>
el.id !== containingFrame && isOfTargetFrame(el, containingFrame),
);
} else if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
@@ -499,10 +503,7 @@ function shiftElementsAccountingForFrames(
}),
);
const frameAwareContiguousElementsToMove: {
regularElements: ExcalidrawElement[];
frameChildren: Map<ExcalidrawFrameLikeElement["id"], ExcalidrawElement[]>;
} = { regularElements: [], frameChildren: new Map() };
const regularElements: ExcalidrawElement[] = [];
const fullySelectedFrames = new Set<ExcalidrawFrameLikeElement["id"]>();
@@ -512,51 +513,33 @@ function shiftElementsAccountingForFrames(
}
}
const selectedFrameIds = new Set<ExcalidrawFrameLikeElement["id"]>();
for (const element of allElements) {
if (elementsToMove.has(element.id)) {
if (
isFrameLikeElement(element) ||
(element.frameId && fullySelectedFrames.has(element.frameId))
) {
frameAwareContiguousElementsToMove.regularElements.push(element);
regularElements.push(element);
} else if (!element.frameId) {
frameAwareContiguousElementsToMove.regularElements.push(element);
} else {
const frameChildren =
frameAwareContiguousElementsToMove.frameChildren.get(
element.frameId,
) || [];
frameChildren.push(element);
frameAwareContiguousElementsToMove.frameChildren.set(
element.frameId,
frameChildren,
);
regularElements.push(element);
} else if (!selectedFrameIds.has(element.frameId)) {
selectedFrameIds.add(element.frameId);
regularElements.push(element);
}
}
}
let nextElements = allElements;
const frameChildrenSets = Array.from(
frameAwareContiguousElementsToMove.frameChildren.entries(),
);
for (const [frameId, children] of frameChildrenSets) {
nextElements = shiftFunction(
allElements,
appState,
direction,
frameId,
children,
);
}
const containingFrame =
selectedFrameIds.size > 0 ? [...selectedFrameIds][0] : null;
return shiftFunction(
nextElements,
allElements,
appState,
direction,
null,
frameAwareContiguousElementsToMove.regularElements,
containingFrame,
regularElements,
);
}