From dedfeec9adabe4867d54a68e99b270bb93337334 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 11 Apr 2024 20:43:26 +0300 Subject: [PATCH] Ensure increasing ordinals of new masks --- ts/routes/image-occlusion/tools/tool-ellipse.ts | 2 +- ts/routes/image-occlusion/tools/tool-polygon.ts | 2 +- ts/routes/image-occlusion/tools/tool-rect.ts | 2 +- ts/routes/image-occlusion/tools/tool-text.ts | 2 +- ts/routes/image-occlusion/tools/tool-undo-redo.ts | 10 +++++++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ts/routes/image-occlusion/tools/tool-ellipse.ts b/ts/routes/image-occlusion/tools/tool-ellipse.ts index 49d8b13a5..eb6a41fae 100644 --- a/ts/routes/image-occlusion/tools/tool-ellipse.ts +++ b/ts/routes/image-occlusion/tools/tool-ellipse.ts @@ -119,7 +119,7 @@ export const drawEllipse = (canvas: fabric.Canvas): void => { ellipse.setCoords(); canvas.setActiveObject(ellipse); - undoStack.onObjectAdded(ellipse.id); + undoStack.onObjectAdded(ellipse); ellipse = undefined; }); }; diff --git a/ts/routes/image-occlusion/tools/tool-polygon.ts b/ts/routes/image-occlusion/tools/tool-polygon.ts index 060da72e9..4f055eeb7 100644 --- a/ts/routes/image-occlusion/tools/tool-polygon.ts +++ b/ts/routes/image-occlusion/tools/tool-polygon.ts @@ -203,7 +203,7 @@ const generatePolygon = (canvas: fabric.Canvas, pointsList): void => { canvas.add(polygon); canvas.setActiveObject(polygon); // view undo redo tools - undoStack.onObjectAdded(polygon["id"]); + undoStack.onObjectAdded(polygon); } toggleDrawPolygon(canvas); diff --git a/ts/routes/image-occlusion/tools/tool-rect.ts b/ts/routes/image-occlusion/tools/tool-rect.ts index 1e042b760..658e1279f 100644 --- a/ts/routes/image-occlusion/tools/tool-rect.ts +++ b/ts/routes/image-occlusion/tools/tool-rect.ts @@ -114,7 +114,7 @@ export const drawRectangle = (canvas: fabric.Canvas): void => { rect.setCoords(); canvas.setActiveObject(rect); - undoStack.onObjectAdded(rect.id); + undoStack.onObjectAdded(rect); rect = undefined; }); }; diff --git a/ts/routes/image-occlusion/tools/tool-text.ts b/ts/routes/image-occlusion/tools/tool-text.ts index e69553202..629ac8e2a 100644 --- a/ts/routes/image-occlusion/tools/tool-text.ts +++ b/ts/routes/image-occlusion/tools/tool-text.ts @@ -50,7 +50,7 @@ export const drawText = (canvas: fabric.Canvas): void => { enableUniformScaling(canvas, text); canvas.add(text); canvas.setActiveObject(text); - undoStack.onObjectAdded(text.id); + undoStack.onObjectAdded(text); text.selectAll(); }); diff --git a/ts/routes/image-occlusion/tools/tool-undo-redo.ts b/ts/routes/image-occlusion/tools/tool-undo-redo.ts index aa073dfe4..8a3a9e64a 100644 --- a/ts/routes/image-occlusion/tools/tool-undo-redo.ts +++ b/ts/routes/image-occlusion/tools/tool-undo-redo.ts @@ -95,11 +95,15 @@ class UndoStack { }); } - onObjectAdded(id: string): void { - if (!this.shapeIds.has(id)) { + onObjectAdded(shape: fabric.Object): void { + if (!this.shapeIds.has(shape.id)) { this.push(); } - this.shapeIds.add(id); + this.shapeIds.add(shape.id); + if (shape.type !== "i-text") { + const ordinals = this.canvas!.getObjects().filter(shape => shape.ordinal).map(shape => shape.ordinal); + shape.ordinal = Math.max(...ordinals, 0) + 1; + } emitChangeSignal(); }