| 5 | } |
| 6 | |
| 7 | export class SelectionBoxController { |
| 8 | private selectionBox: HTMLElement | null = null; |
| 9 | private selectionStartX = 0; |
| 10 | private selectionStartY = 0; |
| 11 | private readonly mouseMoveThreshold = 5; |
| 12 | private mouseMoved = false; |
| 13 | private selectionMode = false; |
| 14 | |
| 15 | constructor(private options: SelectionBoxControllerOptions) {} |
| 16 | |
| 17 | initialize(): void { |
| 18 | this.options.highlightContainer.removeEventListener("mousedown", this.handleSelectionStart); |
| 19 | this.cleanupMouseEvents(); |
| 20 | this.cleanupSelectionEvents(); |
| 21 | this.options.highlightContainer.addEventListener("mousedown", this.handleSelectionStart); |
| 22 | } |
| 23 | |
| 24 | isInSelectionMode(): boolean { |
| 25 | return this.selectionMode; |
| 26 | } |
| 27 | |
| 28 | destroy(): void { |
| 29 | if (this.selectionBox) { |
| 30 | this.selectionBox.remove(); |
| 31 | this.selectionBox = null; |
| 32 | } |
| 33 | |
| 34 | this.options.highlightContainer.removeEventListener("mousedown", this.handleSelectionStart); |
| 35 | this.cleanupMouseEvents(); |
| 36 | this.cleanupSelectionEvents(); |
| 37 | this.selectionMode = false; |
| 38 | } |
| 39 | |
| 40 | private handleSelectionStart = (e: MouseEvent) => { |
| 41 | const target = e.target as HTMLElement; |
| 42 | if (target.closest(".highlight-card") || |
| 43 | target.closest(".flashcard-mode") || |
| 44 | target.closest(".flashcard-add-group") || |
| 45 | target.closest(".flashcard-group-action")) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | this.selectionStartX = e.clientX; |
| 50 | this.selectionStartY = e.clientY; |
| 51 | this.mouseMoved = false; |
| 52 | |
| 53 | activeDocument.addEventListener("mousemove", this.handleMouseMove); |
| 54 | activeDocument.addEventListener("mouseup", this.handleMouseUp); |
| 55 | }; |
| 56 | |
| 57 | private handleMouseMove = (e: MouseEvent) => { |
| 58 | const dx = e.clientX - this.selectionStartX; |
| 59 | const dy = e.clientY - this.selectionStartY; |
| 60 | const distance = Math.sqrt(dx * dx + dy * dy); |
| 61 | |
| 62 | if (distance >= this.mouseMoveThreshold) { |
| 63 | this.mouseMoved = true; |
| 64 | activeDocument.removeEventListener("mousemove", this.handleMouseMove); |
nothing calls this directly
no test coverage detected