Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Handlers/EventHandlers/arrowEndpointHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEffect } from "react";
import { useCanvasContext } from "../../hooks";
import { isArrow } from "../../utils/shapeLabel";
import { attachEndpointControls } from "../../utils/arrowEndpoints";

// Give a selected arrow its endpoint drag-handles back. buildArrowGroup installs
// them (plus hasBorders:false / perPixelTargetFind), but controls aren't
// serialized — so an arrow restored from a saved scene, or rebuilt by an
// undo/redo loadFromJSON, would otherwise show default bbox handles in the wrong
// spots. Re-attaching on selection covers every load path (mirrors
// LineEndpointHandler).
function ArrowEndpointHandler() {
const { canvas } = useCanvasContext();

useEffect(() => {
if (!canvas) return undefined;
const onSelect = () => {
const t = canvas.getActiveObject();
if (t && isArrow(t) && !t.group) {
attachEndpointControls(t);
t.set({ perPixelTargetFind: true, objectCaching: false });
}
};
canvas.on("selection:created", onSelect);
canvas.on("selection:updated", onSelect);
return () => {
canvas.off("selection:created", onSelect);
canvas.off("selection:updated", onSelect);
};
}, [canvas]);
}

export default ArrowEndpointHandler;
1 change: 1 addition & 0 deletions src/Handlers/EventHandlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as SelectionHandler } from "./selectionHandler";
export { default as TextEventHandler } from "./textEventHandler";
export { default as LabelHandler } from "./labelHandler";
export { default as LineEndpointHandler } from "./lineEndpointHandler";
export { default as ArrowEndpointHandler } from "./arrowEndpointHandler";
export { default as DarkColorHandler } from "./darkColorHandler";
export { default as ZoomHandler } from "./zoomHandler";
export { default as PersistenceHandler } from "./persistenceHandler";
Expand Down
2 changes: 2 additions & 0 deletions src/components/Canvas/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SelectionHandler,
LabelHandler,
LineEndpointHandler,
ArrowEndpointHandler,
TextEventHandler,
ZoomHandler,
PersistenceHandler,
Expand All @@ -29,6 +30,7 @@ function Canvas() {
// shape+text regroup happens before the generic empty-text cleanup.
LabelHandler();
LineEndpointHandler();
ArrowEndpointHandler();
TextEventHandler();
ZoomHandler();
PersistenceHandler();
Expand Down
Loading