From ba101ebd0cf971bcd8a7fee22fdbd8d587a47e5a Mon Sep 17 00:00:00 2001
From: fsdavid <daviti1@mail.com>
Date: Fri, 18 Oct 2019 12:27:18 +0200
Subject: [PATCH] cancel on single click

---
 .../takeScreenshot.component.ts               | 38 +++++++++++++++----
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/ui/takeScreenshot/takeScreenshot.component.ts b/src/ui/takeScreenshot/takeScreenshot.component.ts
index e070de583..15909f478 100644
--- a/src/ui/takeScreenshot/takeScreenshot.component.ts
+++ b/src/ui/takeScreenshot/takeScreenshot.component.ts
@@ -1,7 +1,6 @@
 import {Component, ElementRef, HostListener, Inject, Input, OnInit, Renderer2, ViewChild} from "@angular/core";
 import html2canvas from "html2canvas";
 import {DOCUMENT} from "@angular/common";
-import {ESCAPE} from "@angular/cdk/keycodes";
 
 @Component({
     selector: 'take-screenshot',
@@ -10,7 +9,7 @@ import {ESCAPE} from "@angular/cdk/keycodes";
 })
 export class TakeScreenshotComponent implements OnInit {
 
-    @ViewChild('downloadLink', {read: ElementRef}) downloadLink: ElementRef;
+    @ViewChild('downloadLink', {read: ElementRef}) downloadLink: ElementRef
     @ViewChild('helpBody', {read: ElementRef}) helpBody: ElementRef
     @ViewChild('screenshotPreviewCard', {read: ElementRef}) screenshotPreviewCard: ElementRef
     takingScreenshot = false
@@ -163,7 +162,13 @@ export class TakeScreenshotComponent implements OnInit {
         this.loadingScreenshot = true
         this.takingScreenshot = false
 
-        this.takeScreenshot()
+        if (this.boxEndWidth * window.devicePixelRatio <= 1 && this.boxEndHeight * window.devicePixelRatio <= 1) {
+            console.log(1)
+            this.cancelTakingScreenshot()
+        } else {
+            console.log(2)
+            this.takeScreenshot()
+        }
 
     }
 
@@ -186,6 +191,7 @@ export class TakeScreenshotComponent implements OnInit {
             this.loadingScreenshot = false
             this.imageUrl = this.croppedCanvas.toDataURL()
             this.previewingScreenshot = true
+            this.clearStateAfterScreenshot()
         })
     }
 
@@ -196,10 +202,28 @@ export class TakeScreenshotComponent implements OnInit {
     }
 
     cancelTakingScreenshot() {
-        this.takingScreenshot = false;
-        this.previewingScreenshot = false;
-        this.loadingScreenshot = false;
-        this.croppedCanvas = null;
+        this.takingScreenshot = false
+        this.previewingScreenshot = false
+        this.loadingScreenshot = false
+        this.croppedCanvas = null
+    }
+    clearStateAfterScreenshot() {
+        this.mouseIsDown = false
+        this.isDragging = false
+        this.tookScreenShot = false
+        this.startX = 0
+        this.startY = 0
+        this.endX = 0
+        this.endY = 0
+        this.borderWidth = ''
+        this.boxTop = 0
+        this.boxLeft = 0
+        this.boxEndWidth = 0
+        this.boxEndHeight = 0
+        this.windowHeight = 0
+        this.windowWidth = 0
+        this.screenshotStartX = 0
+        this.screenshotStartY = 0
     }
 
 }
\ No newline at end of file
-- 
GitLab