Skip to content

Commit 8798593

Browse files
committed
ok truly fix select
1 parent acfe94f commit 8798593

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

desktop.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
// the selection box thing...
22

33
let selectDragActive = false;
4+
let firstClickSafe = false;
45
const startPosition = { x: 0, y: 0 };
56
const endPosition = { x: 0, y: 0 };
67

78
window.addEventListener("mousemove", (event) => {
89
if (event.buttons & 1) {
10+
if (!selectDragActive && firstClickSafe) {
11+
if (didClickWindow(event.target)) {
12+
return;
13+
}
14+
15+
selectDragActive = true;
16+
startPosition.x = event.clientX;
17+
startPosition.y = event.clientY;
18+
}
19+
920
// Starting a new drag
1021
endPosition.x = event.clientX;
1122
endPosition.y = event.clientY;
@@ -14,10 +25,12 @@ window.addEventListener("mousemove", (event) => {
1425
} else {
1526
selectDragActive = false;
1627
}
28+
1729
displaySelectionBox();
1830
});
1931

2032
window.addEventListener("mouseup", () => {
33+
firstClickSafe = true;
2134
if (selectDragActive) {
2235
selectDragActive = false;
2336
doSelectionBoxLogic(getSanePositions());
@@ -75,7 +88,11 @@ const containedInSelection = (x, y, width, height, positions) => {
7588
return xContained && yContained;
7689
};
7790

78-
const doSelectionBoxLogic = (boxPositions) => {
91+
const doSelectionBoxLogic = (boxPositions, bypassDrag = false) => {
92+
if (!selectDragActive && !bypassDrag) {
93+
return;
94+
}
95+
7996
const desktopItems = Array.from(document.querySelectorAll(".desktop > div"));
8097
desktopItems.forEach((element) => {
8198
const bounds = element.getBoundingClientRect();
@@ -109,15 +126,7 @@ const displaySelectionBox = () => {
109126
};
110127

111128
const desktopClickHandler = (event) => {
112-
if (!selectDragActive) {
113-
if (didClickWindow(event.target)) {
114-
return;
115-
}
116-
117-
selectDragActive = true;
118-
startPosition.x = event.clientX;
119-
startPosition.y = event.clientY;
120-
}
129+
firstClickSafe = !didClickWindow(event.target);
121130

122131
const positions = {
123132
x: event.pageX,
@@ -126,7 +135,7 @@ const desktopClickHandler = (event) => {
126135
height: 1,
127136
};
128137

129-
doSelectionBoxLogic(positions);
138+
doSelectionBoxLogic(positions, true);
130139
};
131140

132141
window.addEventListener("mousedown", desktopClickHandler);

0 commit comments

Comments
 (0)