Browse Source

fix: 鼠标事件多次监听bug

liutian 1 year ago
parent
commit
208bd4e483
2 changed files with 8 additions and 7 deletions
  1. 8 6
      packages/core/src/TextSelection.ts
  2. 0 1
      packages/core/src/pdf_viewer.js

+ 8 - 6
packages/core/src/TextSelection.ts

@@ -95,18 +95,20 @@ export class TextSelection {
 
   set tool (toolType) {
     if (toolType === this._tool) return
-    this._tool = toolType
-    if (!markupType.includes(this.tool)) {
+    if (!markupType.includes(toolType)) {
       document.removeEventListener('mousedown', this.handleMouseDown)
       document.removeEventListener('touchstart', this.handleMouseDown)
       document.removeEventListener('mousemove', this.handleMouseMove)
       document.removeEventListener('touchmove', this.handleMouseMove)
       return
     }
-    document.addEventListener('mousedown', this.handleMouseDown)
-    document.addEventListener('touchstart', this.handleMouseDown)
-    document.addEventListener('mousemove', this.handleMouseMove)
-    document.addEventListener('touchmove', this.handleMouseMove)
+    if (!(markupType.includes(toolType) && markupType.includes(this.tool))) {
+      document.addEventListener('mousedown', this.handleMouseDown)
+      document.addEventListener('touchstart', this.handleMouseDown)
+      document.addEventListener('mousemove', this.handleMouseMove)
+      document.addEventListener('touchmove', this.handleMouseMove)
+    }
+    this._tool = toolType
   }
 
   testPoint(event: MouseEvent) {

+ 0 - 1
packages/core/src/pdf_viewer.js

@@ -1347,7 +1347,6 @@ class PDFViewer {
     if (numVisiblePages === 0) {
       return;
     }
-    console.log(visible)
     const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
     this.#buffer.resize(newCacheSize, visible.ids);