From 0cf3978ead40b97799f7cb637aac0e6daee27c56 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Tue, 31 Mar 2020 14:04:18 +0300 Subject: [PATCH 1/3] Fixed escape in draw --- cvat-canvas/src/typescript/drawHandler.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cvat-canvas/src/typescript/drawHandler.ts b/cvat-canvas/src/typescript/drawHandler.ts index 4afe75ec..f6c1d947 100644 --- a/cvat-canvas/src/typescript/drawHandler.ts +++ b/cvat-canvas/src/typescript/drawHandler.ts @@ -50,6 +50,7 @@ export class DrawHandlerImpl implements DrawHandler { // so, methods like draw() just undefined for SVG.Shape, but nevertheless they exist private drawInstance: any; private initialized: boolean; + private canceled: boolean; private pointsGroup: SVG.G | null; private shapeSizeElement: ShapeSizeElement; @@ -149,6 +150,7 @@ export class DrawHandlerImpl implements DrawHandler { // Clear drawing this.drawInstance.draw('stop'); } + this.drawInstance.off(); this.drawInstance.remove(); this.drawInstance = null; @@ -161,6 +163,7 @@ export class DrawHandlerImpl implements DrawHandler { if (this.crosshair) { this.removeCrosshair(); } + this.onDrawDone(null); } private initDrawing(): void { @@ -175,8 +178,9 @@ export class DrawHandlerImpl implements DrawHandler { const bbox = (e.target as SVGRectElement).getBBox(); const [xtl, ytl, xbr, ybr] = this.getFinalRectCoordinates(bbox); const { shapeType } = this.drawData; - this.cancel(); + this.release(); + if (this.canceled) return; if ((xbr - xtl) * (ybr - ytl) >= consts.AREA_THRESHOLD) { this.onDrawDone({ shapeType, @@ -290,11 +294,11 @@ export class DrawHandlerImpl implements DrawHandler { this.drawInstance.on('drawdone', (e: CustomEvent): void => { const targetPoints = pointsToArray((e.target as SVGElement).getAttribute('points')); - const { points, box } = this.getFinalPolyshapeCoordinates(targetPoints); const { shapeType } = this.drawData; - this.cancel(); + this.release(); + if (this.canceled) return; if (shapeType === 'polygon' && ((box.xbr - box.xtl) * (box.ybr - box.ytl) >= consts.AREA_THRESHOLD) && points.length >= 3 * 2) { @@ -598,6 +602,7 @@ export class DrawHandlerImpl implements DrawHandler { this.canvas = canvas; this.text = text; this.initialized = false; + this.canceled = false; this.drawData = null; this.geometry = null; this.crosshair = null; @@ -671,17 +676,18 @@ export class DrawHandlerImpl implements DrawHandler { this.geometry = geometry; if (drawData.enabled) { + this.canceled = false; this.drawData = drawData; this.initDrawing(); this.startDraw(); } else { - this.cancel(); + this.release(); this.drawData = drawData; } } public cancel(): void { + this.canceled = true; this.release(); - this.onDrawDone(null); } } From 2e6a92afa4fd52c531678bcb2f4cb9f40d1c244f Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Tue, 31 Mar 2020 14:09:47 +0300 Subject: [PATCH 2/3] Insert multiple shapes --- cvat-canvas/src/typescript/drawHandler.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cvat-canvas/src/typescript/drawHandler.ts b/cvat-canvas/src/typescript/drawHandler.ts index f6c1d947..a2c401c5 100644 --- a/cvat-canvas/src/typescript/drawHandler.ts +++ b/cvat-canvas/src/typescript/drawHandler.ts @@ -163,7 +163,10 @@ export class DrawHandlerImpl implements DrawHandler { if (this.crosshair) { this.removeCrosshair(); } - this.onDrawDone(null); + + if (!this.drawData.initialState) { + this.onDrawDone(null); + } } private initDrawing(): void { From d578f1773ad2db83b41d1d5a9592885a1d5137c0 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Tue, 31 Mar 2020 22:24:07 +0300 Subject: [PATCH 3/3] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f15c960..b7430563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ### Fixed -- +- New shape is added when press ``esc`` when drawing instead of cancellation ### Security -