@@ -500,14 +500,17 @@ export interface TerminalSelectionClickSequence {
500500 readonly y : number ;
501501}
502502
503+ const TERMINAL_LINK_DRAG_THRESHOLD_PX = 4 ;
504+
503505export function advanceTerminalSelectionClickSequence (
504506 previous : TerminalSelectionClickSequence | null ,
505507 event : Pick < PointerEvent , "clientX" | "clientY" | "timeStamp" > ,
506508) : TerminalSelectionClickSequence {
507509 const repeats =
508510 previous !== null &&
509511 event . timeStamp - previous . time <= SELECTION_MULTI_CLICK_INTERVAL_MS &&
510- Math . hypot ( event . clientX - previous . x , event . clientY - previous . y ) <= 4 ;
512+ Math . hypot ( event . clientX - previous . x , event . clientY - previous . y ) <=
513+ TERMINAL_LINK_DRAG_THRESHOLD_PX ;
511514 return {
512515 count : repeats ? ( previous . count >= 3 ? 1 : previous . count + 1 ) : 1 ,
513516 time : event . timeStamp ,
@@ -593,7 +596,11 @@ export class GhosttyTerminalSurface {
593596 private mouseReportingButton : number | null = null ;
594597 private linkActivationPointerId : number | null = null ;
595598 private linkActivationLink : TerminalLinkWithRange | null = null ;
596- private linkActivationOrigin : { x : number ; y : number ; time : number } | null = null ;
599+ private linkActivationOrigin : {
600+ x : number ;
601+ y : number ;
602+ clickCount : number ;
603+ } | null = null ;
597604 private hoveredLink : TerminalLinkWithRange | null = null ;
598605 private hoverPointer : { x : number ; y : number } | null = null ;
599606 private selectionClickSequence : TerminalSelectionClickSequence | null = null ;
@@ -1262,33 +1269,39 @@ export class GhosttyTerminalSurface {
12621269 return ;
12631270 }
12641271 if ( event . button !== 0 ) return ;
1272+ const clickCount = this . recordSelectionClick ( event ) ;
12651273 const link = this . linkAt ( event . clientX , event . clientY ) ;
1266- if ( link ) {
1274+ if ( link && ! event . shiftKey && clickCount === 1 ) {
12671275 event . preventDefault ( ) ;
12681276 event . stopPropagation ( ) ;
12691277 this . linkActivationPointerId = event . pointerId ;
12701278 this . linkActivationLink = link ;
12711279 this . linkActivationOrigin = {
12721280 x : event . clientX ,
12731281 y : event . clientY ,
1274- time : event . timeStamp ,
1282+ clickCount ,
12751283 } ;
12761284 this . canvas . setPointerCapture ( event . pointerId ) ;
12771285 return ;
12781286 }
12791287 this . clearHoveredLink ( ) ;
1280- this . beginSelection ( event ) ;
1288+ this . beginSelection ( event , clickCount ) ;
12811289 this . canvas . setPointerCapture ( event . pointerId ) ;
12821290 } ;
12831291
1284- private beginSelection ( event : { clientX : number ; clientY : number ; timeStamp : number } ) : void {
1285- const cell = this . cellAt ( event . clientX , event . clientY ) ;
1286- this . selectionMoved = false ;
1292+ private recordSelectionClick (
1293+ event : Pick < PointerEvent , " clientX" | " clientY" | "timeStamp" > ,
1294+ ) : number {
12871295 this . selectionClickSequence = advanceTerminalSelectionClickSequence (
12881296 this . selectionClickSequence ,
12891297 event ,
12901298 ) ;
1291- const clickCount = this . selectionClickSequence . count ;
1299+ return this . selectionClickSequence . count ;
1300+ }
1301+
1302+ private beginSelection ( event : { clientX : number ; clientY : number } , clickCount : number ) : void {
1303+ const cell = this . cellAt ( event . clientX , event . clientY ) ;
1304+ this . selectionMoved = false ;
12921305 this . selectionMode = clickCount >= 3 ? "line" : clickCount === 2 ? "word" : "cell" ;
12931306 const range =
12941307 this . selectionMode === "line"
@@ -1322,16 +1335,24 @@ export class GhosttyTerminalSurface {
13221335 private readonly onPointerMove = ( event : PointerEvent ) => {
13231336 if ( this . linkActivationPointerId === event . pointerId ) {
13241337 const origin = this . linkActivationOrigin ;
1325- if ( origin === null || ( event . clientX === origin . x && event . clientY === origin . y ) ) return ;
1338+ if (
1339+ origin === null ||
1340+ Math . hypot ( event . clientX - origin . x , event . clientY - origin . y ) <=
1341+ TERMINAL_LINK_DRAG_THRESHOLD_PX
1342+ ) {
1343+ return ;
1344+ }
13261345 this . linkActivationPointerId = null ;
13271346 this . linkActivationLink = null ;
13281347 this . linkActivationOrigin = null ;
13291348 this . clearHoveredLink ( ) ;
1330- this . beginSelection ( {
1331- clientX : origin . x ,
1332- clientY : origin . y ,
1333- timeStamp : origin . time ,
1334- } ) ;
1349+ this . beginSelection (
1350+ {
1351+ clientX : origin . x ,
1352+ clientY : origin . y ,
1353+ } ,
1354+ origin . clickCount ,
1355+ ) ;
13351356 }
13361357 // Hover motion is only reportable in any-event tracking (DEC 1003); normal and
13371358 // button-event tracking never report motion without a captured pressed button.
0 commit comments