@@ -9,9 +9,15 @@ export default class SelectionCore {
9
9
touchStartY = 0 ;
10
10
touchStartTime = 0 ;
11
11
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
+ ) {
15
21
this . terminal = terminal ;
16
22
this . startHandle = startHandle ;
17
23
this . endHandle = endHandle ;
@@ -23,7 +29,7 @@ export default class SelectionCore {
23
29
const renderer = this . terminal . _core . _renderService . dimensions ;
24
30
return {
25
31
cellWidth : renderer . css . cell . width ,
26
- cellHeight : renderer . css . cell . height
32
+ cellHeight : renderer . css . cell . height ,
27
33
} ;
28
34
}
29
35
@@ -74,18 +80,20 @@ export default class SelectionCore {
74
80
handle.style.top = `${y}px`;
75
81
handle.style.display = 'block';
76
82
}*/
77
-
83
+
78
84
setHandlePosition ( handle , row , column , isStartHandle = false ) {
79
85
const { cellWidth, cellHeight } = this . _getCellSize ( ) ;
80
86
const rect = this . terminal . element . getBoundingClientRect ( ) ;
81
87
82
88
const terminalContainer = this . terminalContainer ;
83
89
const terminalHeader = this . terminalHeader ;
84
-
90
+
85
91
// Heights
86
92
const terminalContainerRect = terminalContainer . getBoundingClientRect ( ) ;
87
- const terminalHeaderHeight = terminalHeader ? terminalHeader . getBoundingClientRect ( ) . height : 0 ;
88
-
93
+ const terminalHeaderHeight = terminalHeader
94
+ ? terminalHeader . getBoundingClientRect ( ) . height
95
+ : 0 ;
96
+
89
97
// Terminal scroll position and viewport Y-offset
90
98
const terminalScrollOffset = this . terminal . element . scrollTop || 0 ;
91
99
const viewportScrollOffset = this . terminal . buffer . active . viewportY ;
@@ -95,13 +103,20 @@ export default class SelectionCore {
95
103
96
104
// X position based on column
97
105
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 ;
100
108
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 ;
102
115
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 ) ;
105
120
106
121
if ( isSwapped ) {
107
122
x = ! isStartHandle
@@ -111,22 +126,25 @@ export default class SelectionCore {
111
126
112
127
// Ensure the handle stays within bounds of terminal
113
128
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
+ ) ;
115
133
116
134
// Set the position of the handle
117
135
handle . style . left = `${ x } px` ;
118
136
handle . style . top = `${ y } px` ;
119
- handle . style . display = ' block' ;
137
+ handle . style . display = " block" ;
120
138
}
121
139
122
140
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" ;
125
143
}
126
144
127
145
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" ;
130
148
}
131
149
132
150
startSelection ( row , column ) {
@@ -150,29 +168,47 @@ export default class SelectionCore {
150
168
151
169
// start is always before end in the terminal's text flow
152
170
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
+ ] ;
154
177
}
155
178
156
- const totalLength = this . _calculateTotalSelectionLength ( startRow , endRow , startColumn , endColumn ) ;
179
+ const totalLength = this . _calculateTotalSelectionLength (
180
+ startRow ,
181
+ endRow ,
182
+ startColumn ,
183
+ endColumn ,
184
+ ) ;
157
185
this . terminal . select ( startColumn , startRow , totalLength ) ;
158
186
159
187
// 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
+ ) ;
162
199
}
163
200
164
201
_calculateTotalSelectionLength ( startRow , endRow , startColumn , endColumn ) {
165
202
const terminalCols = this . terminal . cols ;
166
203
167
204
if ( startRow === endRow ) {
168
205
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 ;
175
206
}
207
+ let length = 0 ;
208
+ length += terminalCols - startColumn ;
209
+ length += ( endRow - startRow - 1 ) * terminalCols ;
210
+ length += endColumn + 1 ;
211
+ return length ;
176
212
}
177
213
178
214
startHandleTouchMoveCb ( event ) {
@@ -204,7 +240,7 @@ export default class SelectionCore {
204
240
205
241
this . tapHoldTimeout = setTimeout ( ( ) => {
206
242
this . isTapAndHoldActive = true ;
207
- this . terminal . focus ( )
243
+ this . terminal . focus ( ) ;
208
244
this . startSelection ( coords . row , coords . column ) ;
209
245
} , 500 ) ;
210
246
}
@@ -223,7 +259,10 @@ export default class SelectionCore {
223
259
const touchMoveDelta = Math . abs ( this . touchMoveY - this . touchStartY ) ;
224
260
const touchMoveTime = Date . now ( ) - this . touchStartTime ;
225
261
226
- if ( touchMoveDelta > this . scrollThreshold && touchMoveTime < this . scrollTimeThreshold ) {
262
+ if (
263
+ touchMoveDelta > this . scrollThreshold &&
264
+ touchMoveTime < this . scrollTimeThreshold
265
+ ) {
227
266
clearTimeout ( this . tapHoldTimeout ) ;
228
267
}
229
268
}
@@ -251,4 +290,4 @@ export default class SelectionCore {
251
290
this . hideHandles ( ) ;
252
291
}
253
292
}
254
- }
293
+ }
0 commit comments