fix(editor): take arrows out of frames when nudged or moved from the stats panel

The arrow keys and the stats panel move arrows too, so check there as well
whether a moved arrow still has an end in its frame.

Claude Opus 5.5 (xhigh reasoning)
This commit is contained in:
dwelle committed 2026-11-02 09:53:42 +01:00
1 parent 986c195625
commit a32da2dfce
3 files changed
+55

No files matched your search

+42
View File
@@ -1546,6 +1546,48 @@ describe("arrows in frames", () => {
expect(arrow.frameId).toBe(null);
});
/** an arrow in frame A, just inside its right edge */
const createArrowAtFrameEdge = () => {
const arrow = API.createElement({
type: "arrow",
x: 291,
y: 50,
width: 5,
height: 0,
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(5, 0)],
frameId: frameA.id,
});
API.setElements([...h.elements, arrow]);
API.setSelectedElements([arrow]);
return arrow;
};
it("should take an arrow out of its frame when nudging its ends out of it", () => {
const arrow = createArrowAtFrameEdge();
Keyboard.withModifierKeys({ shift: true }, () => {
Keyboard.keyPress(KEYS.ARROW_RIGHT);
});
expect(arrow.frameId).toBe(frameA.id);
Keyboard.withModifierKeys({ shift: true }, () => {
Keyboard.keyPress(KEYS.ARROW_RIGHT);
});
expect(arrow.frameId).toBe(null);
});
it("should take an arrow out of its frame when moving its ends out of it from the stats panel", () => {
const arrow = createArrowAtFrameEdge();
API.setAppState({ stats: { ...h.state.stats, open: true } });
UI.updateInput(
UI.queryStatsProperty("X")!.querySelector(".drag-input")!,
"350",
);
expect(arrow.x).toBe(350);
expect(arrow.frameId).toBe(null);
});
it("should take an arrow out of its frame when resizing the frame leaves its ends out", () => {
const arrow = drawArrowBetweenFrames();
+6
View File
@@ -163,6 +163,7 @@ import {
isFrameClippable,
addElementsToFrame,
replaceAllElementsInFrame,
removeArrowsWithoutEndInFrame,
removeElementsFromFrame,
getElementsInResizingFrame,
getElementsInNewFrame,
@@ -5479,6 +5480,11 @@ class App extends React.Component<AppProps, AppState> {
moveFrameArrows(frameArrowIds, { x: offsetX, y: offsetY }, this.scene, {
renderEnvironment: this.renderEnvironment,
});
// a moved arrow's ends may have left its frame
removeArrowsWithoutEndInFrame(
movedElements,
this.scene.getNonDeletedElementsMap(),
);
this.scene.triggerUpdate();
@@ -19,6 +19,7 @@ import { getFrameChildren } from "@excalidraw/element";
import {
getFrameArrowIdsToReattach,
moveFrameArrows,
removeArrowsWithoutEndInFrame,
updateBindings,
} from "@excalidraw/element";
import { DRAGGING_THRESHOLD } from "@excalidraw/common";
@@ -246,6 +247,12 @@ export const moveElement = (
renderEnvironment,
});
}
// a moved arrow's ends may have left its frame
removeArrowsWithoutEndInFrame(
[latestElement],
scene.getNonDeletedElementsMap(),
);
};
export const getAtomicUnits = (