mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-22 00:41:09 +02:00
fix: Elbow arrow fixes
This commit is contained in:
@@ -145,6 +145,7 @@ export const bindOrUnbindBindingElement = (
|
|||||||
...opts,
|
...opts,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
bindOrUnbindBindingElementEdge(arrow, start, "start", scene);
|
bindOrUnbindBindingElementEdge(arrow, start, "start", scene);
|
||||||
bindOrUnbindBindingElementEdge(arrow, end, "end", scene);
|
bindOrUnbindBindingElementEdge(arrow, end, "end", scene);
|
||||||
if (!isElbowArrow(arrow) && (start.focusPoint || end.focusPoint)) {
|
if (!isElbowArrow(arrow) && (start.focusPoint || end.focusPoint)) {
|
||||||
|
@@ -155,8 +155,8 @@ describe("elbow arrow routing", () => {
|
|||||||
expect(arrow.width).toEqual(90);
|
expect(arrow.width).toEqual(90);
|
||||||
expect(arrow.height).toEqual(200);
|
expect(arrow.height).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can generate proper points for bound elbow arrow", () => {
|
it("can generate proper points for bound elbow arrow", () => {
|
||||||
const scene = new Scene();
|
|
||||||
const rectangle1 = API.createElement({
|
const rectangle1 = API.createElement({
|
||||||
type: "rectangle",
|
type: "rectangle",
|
||||||
x: -150,
|
x: -150,
|
||||||
@@ -180,17 +180,15 @@ describe("elbow arrow routing", () => {
|
|||||||
height: 200,
|
height: 200,
|
||||||
points: [pointFrom(0, 0), pointFrom(90, 200)],
|
points: [pointFrom(0, 0), pointFrom(90, 200)],
|
||||||
}) as ExcalidrawElbowArrowElement;
|
}) as ExcalidrawElbowArrowElement;
|
||||||
scene.insertElement(rectangle1);
|
API.setElements([rectangle1, rectangle2, arrow]);
|
||||||
scene.insertElement(rectangle2);
|
|
||||||
scene.insertElement(arrow);
|
|
||||||
|
|
||||||
bindBindingElement(arrow, rectangle1, "orbit", "start", scene);
|
bindBindingElement(arrow, rectangle1, "orbit", "start", h.scene);
|
||||||
bindBindingElement(arrow, rectangle2, "orbit", "end", scene);
|
bindBindingElement(arrow, rectangle2, "orbit", "end", h.scene);
|
||||||
|
|
||||||
expect(arrow.startBinding).not.toBe(null);
|
expect(arrow.startBinding).not.toBe(null);
|
||||||
expect(arrow.endBinding).not.toBe(null);
|
expect(arrow.endBinding).not.toBe(null);
|
||||||
|
|
||||||
h.app.scene.mutateElement(arrow, {
|
h.scene.mutateElement(arrow, {
|
||||||
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(90, 200)],
|
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(90, 200)],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -759,6 +759,27 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.actionManager.registerAction(createRedoAction(this.history));
|
this.actionManager.registerAction(createRedoAction(this.history));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setState: React.Component<AppProps, AppState>["setState"] = (
|
||||||
|
// state,
|
||||||
|
// callback?,
|
||||||
|
// ) => {
|
||||||
|
// let newState: Parameters<typeof this.setState>[0] = null;
|
||||||
|
// if (typeof state === "function") {
|
||||||
|
// newState = state(this.state, this.props) as Pick<
|
||||||
|
// AppState,
|
||||||
|
// keyof AppState
|
||||||
|
// >;
|
||||||
|
// } else {
|
||||||
|
// newState = state as Pick<AppState, keyof AppState>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (newState && Object.hasOwn(newState, "selectedLinearElement")) {
|
||||||
|
// console.trace(!!newState.selectedLinearElement);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// super.setState(newState, callback);
|
||||||
|
// };
|
||||||
|
|
||||||
updateEditorAtom = <Value, Args extends unknown[], Result>(
|
updateEditorAtom = <Value, Args extends unknown[], Result>(
|
||||||
atom: WritableAtom<Value, Args, Result>,
|
atom: WritableAtom<Value, Args, Result>,
|
||||||
...args: Args
|
...args: Args
|
||||||
@@ -2492,47 +2513,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return this.setState(...args);
|
return this.setState(...args);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watchState: {
|
|
||||||
configurable: true,
|
|
||||||
value: (
|
|
||||||
callback:
|
|
||||||
| ((
|
|
||||||
prevState: Parameters<typeof setState>,
|
|
||||||
nextState: Parameters<typeof setState> | null,
|
|
||||||
) => void)
|
|
||||||
| undefined,
|
|
||||||
) => {
|
|
||||||
if (callback) {
|
|
||||||
(window as any).__originalSetState = this.setState;
|
|
||||||
this.setState = new Proxy(this.setState, {
|
|
||||||
apply: (target, thisArg, [state, cb]) => {
|
|
||||||
const prevState = thisArg.state;
|
|
||||||
let newState: Parameters<typeof setState> | null = null;
|
|
||||||
|
|
||||||
// Log state change for debugging
|
|
||||||
if (typeof state === "function") {
|
|
||||||
newState = state(prevState, this.props);
|
|
||||||
} else if (state) {
|
|
||||||
newState = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
callback(prevState, newState);
|
|
||||||
} catch (error) {
|
|
||||||
console.warn("Error in watchState callback:", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newState) {
|
|
||||||
target.bind(thisArg)(newState as any, cb);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if ((window as any).__originalSetState) {
|
|
||||||
this.setState = (window as any).__originalSetState;
|
|
||||||
delete (window as any).__originalSetState;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
app: {
|
app: {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
value: this,
|
value: this,
|
||||||
@@ -7971,7 +7951,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
lastCommittedPoint:
|
lastCommittedPoint:
|
||||||
multiElement.points[multiElement.points.length - 1],
|
multiElement.points[multiElement.points.length - 1],
|
||||||
});
|
});
|
||||||
this.actionManager.executeAction(actionFinalize);
|
this.actionManager.executeAction(actionFinalize, "ui", {
|
||||||
|
event: event.nativeEvent,
|
||||||
|
sceneCoords: {
|
||||||
|
x: pointerDownState.origin.x,
|
||||||
|
y: pointerDownState.origin.y,
|
||||||
|
},
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8158,7 +8144,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState((prevState) => {
|
this.setState((prevState) => {
|
||||||
let linearElementEditor = null;
|
let linearElementEditor = null;
|
||||||
let nextSelectedElementIds = prevState.selectedElementIds;
|
let nextSelectedElementIds = prevState.selectedElementIds;
|
||||||
if (isSimpleArrow(element)) {
|
if (isBindingElement(element)) {
|
||||||
const linearElement = new LinearElementEditor(
|
const linearElement = new LinearElementEditor(
|
||||||
element,
|
element,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
Reference in New Issue
Block a user