@@ -9,9 +9,15 @@ export default class SelectionCore {
99 touchStartY = 0 ;
1010 touchStartTime = 0 ;
1111 scrollThreshold = 10 ; // pixels
12- scrollTimeThreshold = 100 ; // milliseconds
13-
14- constructor ( terminal , startHandle , endHandle , terminalContainer , terminalHeader ) {
12+ scrollTimeThreshold = 100 ; // milliseconds
13+
14+ constructor (
15+ terminal ,
16+ startHandle ,
17+ endHandle ,
18+ terminalContainer ,
19+ terminalHeader ,
20+ ) {
1521 this . terminal = terminal ;
1622 this . startHandle = startHandle ;
1723 this . endHandle = endHandle ;
@@ -23,7 +29,7 @@ export default class SelectionCore {
2329 const renderer = this . terminal . _core . _renderService . dimensions ;
2430 return {
2531 cellWidth : renderer . css . cell . width ,
26- cellHeight : renderer . css . cell . height
32+ cellHeight : renderer . css . cell . height ,
2733 } ;
2834 }
2935
@@ -74,18 +80,20 @@ export default class SelectionCore {
7480 handle.style.top = `${y}px`;
7581 handle.style.display = 'block';
7682 }*/
77-
83+
7884 setHandlePosition ( handle , row , column , isStartHandle = false ) {
7985 const { cellWidth, cellHeight } = this . _getCellSize ( ) ;
8086 const rect = this . terminal . element . getBoundingClientRect ( ) ;
8187
8288 const terminalContainer = this . terminalContainer ;
8389 const terminalHeader = this . terminalHeader ;
84-
90+
8591 // Heights
8692 const terminalContainerRect = terminalContainer . getBoundingClientRect ( ) ;
87- const terminalHeaderHeight = terminalHeader ? terminalHeader . getBoundingClientRect ( ) . height : 0 ;
88-
93+ const terminalHeaderHeight = terminalHeader
94+ ? terminalHeader . getBoundingClientRect ( ) . height
95+ : 0 ;
96+
8997 // Terminal scroll position and viewport Y-offset
9098 const terminalScrollOffset = this . terminal . element . scrollTop || 0 ;
9199 const viewportScrollOffset = this . terminal . buffer . active . viewportY ;
@@ -95,13 +103,20 @@ export default class SelectionCore {
95103
96104 // X position based on column
97105 let x = isStartHandle
98- ? rect . left + column * cellWidth - 10
99- : rect . left + ( column + 1 ) * cellWidth - cellWidth ;
106+ ? rect . left + column * cellWidth - 10
107+ : rect . left + ( column + 1 ) * cellWidth - cellWidth ;
100108
101- let y = rect . top + ( adjustedRow * cellHeight ) - terminalHeaderHeight - terminalScrollOffset - cellHeight ;
109+ let y =
110+ rect . top +
111+ adjustedRow * cellHeight -
112+ terminalHeaderHeight -
113+ terminalScrollOffset -
114+ cellHeight ;
102115
103- const isSwapped = this . selectionStart . row > this . selectionEnd . row ||
104- ( this . selectionStart . row === this . selectionEnd . row && this . selectionStart . column > this . selectionEnd . column ) ;
116+ const isSwapped =
117+ this . selectionStart . row > this . selectionEnd . row ||
118+ ( this . selectionStart . row === this . selectionEnd . row &&
119+ this . selectionStart . column > this . selectionEnd . column ) ;
105120
106121 if ( isSwapped ) {
107122 x = ! isStartHandle
@@ -111,22 +126,25 @@ export default class SelectionCore {
111126
112127 // Ensure the handle stays within bounds of terminal
113128 x = Math . max ( rect . left , Math . min ( x , rect . right - handle . offsetWidth ) ) ;
114- y = Math . max ( terminalContainerRect . top , Math . min ( y , terminalContainerRect . bottom - handle . offsetHeight ) ) ;
129+ y = Math . max (
130+ terminalContainerRect . top ,
131+ Math . min ( y , terminalContainerRect . bottom - handle . offsetHeight ) ,
132+ ) ;
115133
116134 // Set the position of the handle
117135 handle . style . left = `${ x } px` ;
118136 handle . style . top = `${ y } px` ;
119- handle . style . display = ' block' ;
137+ handle . style . display = " block" ;
120138 }
121139
122140 hideHandles ( ) {
123- this . startHandle . style . display = ' none' ;
124- this . endHandle . style . display = ' none' ;
141+ this . startHandle . style . display = " none" ;
142+ this . endHandle . style . display = " none" ;
125143 }
126144
127145 showHandles ( ) {
128- this . startHandle . style . display = ' block' ;
129- this . endHandle . style . display = ' block' ;
146+ this . startHandle . style . display = " block" ;
147+ this . endHandle . style . display = " block" ;
130148 }
131149
132150 startSelection ( row , column ) {
@@ -150,29 +168,47 @@ export default class SelectionCore {
150168
151169 // start is always before end in the terminal's text flow
152170 if ( startRow > endRow || ( startRow === endRow && startColumn > endColumn ) ) {
153- [ startRow , startColumn , endRow , endColumn ] = [ endRow , endColumn , startRow , startColumn ] ;
171+ [ startRow , startColumn , endRow , endColumn ] = [
172+ endRow ,
173+ endColumn ,
174+ startRow ,
175+ startColumn ,
176+ ] ;
154177 }
155178
156- const totalLength = this . _calculateTotalSelectionLength ( startRow , endRow , startColumn , endColumn ) ;
179+ const totalLength = this . _calculateTotalSelectionLength (
180+ startRow ,
181+ endRow ,
182+ startColumn ,
183+ endColumn ,
184+ ) ;
157185 this . terminal . select ( startColumn , startRow , totalLength ) ;
158186
159187 // Set handle positions based on their actual positions, not the selection bounds
160- this . setHandlePosition ( this . startHandle , this . selectionStart . row , this . selectionStart . column , true ) ;
161- this . setHandlePosition ( this . endHandle , this . selectionEnd . row , this . selectionEnd . column ) ;
188+ this . setHandlePosition (
189+ this . startHandle ,
190+ this . selectionStart . row ,
191+ this . selectionStart . column ,
192+ true ,
193+ ) ;
194+ this . setHandlePosition (
195+ this . endHandle ,
196+ this . selectionEnd . row ,
197+ this . selectionEnd . column ,
198+ ) ;
162199 }
163200
164201 _calculateTotalSelectionLength ( startRow , endRow , startColumn , endColumn ) {
165202 const terminalCols = this . terminal . cols ;
166203
167204 if ( startRow === endRow ) {
168205 return Math . abs ( endColumn - startColumn ) + 1 ;
169- } else {
170- let length = 0 ;
171- length += terminalCols - startColumn ;
172- length += ( endRow - startRow - 1 ) * terminalCols ;
173- length += endColumn + 1 ;
174- return length ;
175206 }
207+ let length = 0 ;
208+ length += terminalCols - startColumn ;
209+ length += ( endRow - startRow - 1 ) * terminalCols ;
210+ length += endColumn + 1 ;
211+ return length ;
176212 }
177213
178214 startHandleTouchMoveCb ( event ) {
@@ -204,7 +240,7 @@ export default class SelectionCore {
204240
205241 this . tapHoldTimeout = setTimeout ( ( ) => {
206242 this . isTapAndHoldActive = true ;
207- this . terminal . focus ( )
243+ this . terminal . focus ( ) ;
208244 this . startSelection ( coords . row , coords . column ) ;
209245 } , 500 ) ;
210246 }
@@ -223,7 +259,10 @@ export default class SelectionCore {
223259 const touchMoveDelta = Math . abs ( this . touchMoveY - this . touchStartY ) ;
224260 const touchMoveTime = Date . now ( ) - this . touchStartTime ;
225261
226- if ( touchMoveDelta > this . scrollThreshold && touchMoveTime < this . scrollTimeThreshold ) {
262+ if (
263+ touchMoveDelta > this . scrollThreshold &&
264+ touchMoveTime < this . scrollTimeThreshold
265+ ) {
227266 clearTimeout ( this . tapHoldTimeout ) ;
228267 }
229268 }
@@ -251,4 +290,4 @@ export default class SelectionCore {
251290 this . hideHandles ( ) ;
252291 }
253292 }
254- }
293+ }
0 commit comments