Skip to content

Commit 6bbd56a

Browse files
fix: BROS-478: Undo for Vector (#8835)
Co-authored-by: nick-skriabin <[email protected]>
1 parent 9c9bf20 commit 6bbd56a

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

web/libs/editor/src/components/KonvaVector/KonvaVector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,8 @@ export const KonvaVector = forwardRef<KonvaVectorRef, KonvaVectorProps>((props,
32163216
disabled,
32173217
transformMode,
32183218
disableInternalPointAddition,
3219+
handleTransformStart,
3220+
handleTransformEnd,
32193221
pointCreationManager,
32203222
});
32213223

web/libs/editor/src/components/KonvaVector/eventHandlers/mouseHandlers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ export function createMouseDownHandler(props: EventHandlerProps, handledSelectio
212212
controlIndex: 1,
213213
});
214214
props.isDragging.current = true;
215+
// Fire transform start event when control point dragging begins
216+
props.handleTransformStart?.();
215217
props.lastPos.current = {
216218
x: e.evt.clientX,
217219
y: e.evt.clientY,
@@ -233,6 +235,8 @@ export function createMouseDownHandler(props: EventHandlerProps, handledSelectio
233235
controlIndex: 2,
234236
});
235237
props.isDragging.current = true;
238+
// Fire transform start event when control point dragging begins
239+
props.handleTransformStart?.();
236240
props.lastPos.current = {
237241
x: e.evt.clientX,
238242
y: e.evt.clientY,
@@ -448,6 +452,8 @@ export function createMouseMoveHandler(props: EventHandlerProps, handledSelectio
448452
// If we haven't started dragging yet, check if we should start
449453
if (!props.isDragging.current && (mouseDeltaX > dragThreshold || mouseDeltaY > dragThreshold)) {
450454
props.isDragging.current = true;
455+
// Fire transform start event when point dragging begins
456+
props.handleTransformStart?.();
451457
}
452458

453459
// Only proceed with dragging if we're actually dragging
@@ -775,6 +781,13 @@ export function createMouseUpHandler(props: EventHandlerProps) {
775781
}
776782
}
777783

784+
// Fire transform end event if we were dragging (point or control point)
785+
const wasDragging =
786+
props.isDragging.current || props.draggedPointIndex !== null || props.draggedControlPoint !== null;
787+
if (wasDragging) {
788+
props.handleTransformEnd?.(e);
789+
}
790+
778791
// Reset dragging state
779792
props.isDragging.current = false;
780793
props.setDraggedPointIndex(null);

web/libs/editor/src/components/KonvaVector/eventHandlers/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ export interface EventHandlerProps {
107107
disabled?: boolean;
108108
transformMode?: boolean;
109109
disableInternalPointAddition?: boolean;
110+
handleTransformStart?: () => void;
111+
handleTransformEnd?: (e?: KonvaEventObject<MouseEvent>) => void;
110112
pointCreationManager?: {
111113
isCreating: () => boolean;
112114
createRegularPointAt: (x: number, y: number, prevPointId?: string) => boolean;

web/libs/editor/src/tools/Vector.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ const _Tool = types
264264

265265
const currentArea = area && isAlive(area) ? area : null;
266266

267+
self.annotation.history.freeze();
268+
267269
// Only create new region if we don't have an existing one
268270
if (!currentArea) {
269271
self.currentArea = self.createRegion(self.createRegionOptions(), true);
@@ -318,6 +320,7 @@ const _Tool = types
318320
// skipping a frame to let KonvaVector render and update properly
319321
setTimeout(() => {
320322
self.currentArea?.commitPoint?.(rx, ry);
323+
self.annotation.history.unfreeze();
321324
self.finishDrawing();
322325
});
323326
},

0 commit comments

Comments
 (0)