11// the selection box thing...
22
33let selectDragActive = false ;
4+ let firstClickSafe = false ;
45const startPosition = { x : 0 , y : 0 } ;
56const endPosition = { x : 0 , y : 0 } ;
67
78window . 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
2032window . 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
111128const 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
132141window . addEventListener ( "mousedown" , desktopClickHandler ) ;
0 commit comments