MCPcopy Create free account
hub / github.com/CatMuse/HiNote / SelectionBoxController

Class SelectionBoxController

src/views/selection/SelectionBoxController.ts:7–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5}
6
7export 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);

Callers

nothing calls this directly

Calls 7

startSelectionMethod · 0.95
cleanupMouseEventsMethod · 0.95
selectCardsInBoxMethod · 0.95
clearSelectionMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected