@@ -38,6 +38,32 @@ function getTextRect(
38
38
return { x, y, width, height } ;
39
39
}
40
40
41
+ function isOverLinkText ( e : {
42
+ readonly cell : UriCell ;
43
+ readonly posX : number ;
44
+ readonly posY : number ;
45
+ readonly bounds : Rectangle ;
46
+ readonly theme : FullTheme ;
47
+ } ) : boolean {
48
+ const { cell, bounds, posX, posY, theme } = e ;
49
+ const txt = cell . displayData ?? cell . data ;
50
+ if ( cell . hoverEffect !== true || cell . onClickUri === undefined ) return false ;
51
+
52
+ const m = getMeasuredTextCache ( txt , theme . baseFontFull ) ;
53
+ if ( m === undefined ) return false ;
54
+ const textRect = getTextRect ( m , bounds , theme , cell . contentAlign ) ;
55
+ return pointInRect (
56
+ {
57
+ x : textRect . x - 4 ,
58
+ y : textRect . y - 4 ,
59
+ width : textRect . width + 8 ,
60
+ height : textRect . height + 8 ,
61
+ } ,
62
+ posX ,
63
+ posY
64
+ ) ;
65
+ }
66
+
41
67
export const uriCellRenderer : InternalCellRenderer < UriCell > = {
42
68
getAccessibilityString : c => c . data ?. toString ( ) ?? "" ,
43
69
kind : GridCellKind . Uri ,
@@ -82,26 +108,16 @@ export const uriCellRenderer: InternalCellRenderer<UriCell> = {
82
108
ctx . fillStyle = isLinky ? theme . linkColor : theme . textDark ;
83
109
drawTextCell ( a , txt , cell . contentAlign ) ;
84
110
} ,
111
+ onSelect : e => {
112
+ if ( isOverLinkText ( e ) ) {
113
+ e . preventDefault ( ) ;
114
+ }
115
+ } ,
85
116
onClick : a => {
86
- const { cell, bounds, posX, posY, theme } = a ;
87
- const txt = cell . displayData ?? cell . data ;
88
- if ( cell . hoverEffect !== true || cell . onClickUri === undefined ) return ;
89
-
90
- const m = getMeasuredTextCache ( txt , theme . baseFontFull ) ;
91
- if ( m === undefined ) return ;
92
- const textRect = getTextRect ( m , bounds , theme , cell . contentAlign ) ;
93
- const didClick = pointInRect (
94
- {
95
- x : textRect . x - 4 ,
96
- y : textRect . y - 4 ,
97
- width : textRect . width + 8 ,
98
- height : textRect . height + 8 ,
99
- } ,
100
- posX ,
101
- posY
102
- ) ;
117
+ const { cell } = a ;
118
+ const didClick = isOverLinkText ( a ) ;
103
119
if ( didClick ) {
104
- cell . onClickUri ( a ) ;
120
+ cell . onClickUri ?. ( a ) ;
105
121
}
106
122
return undefined ;
107
123
} ,
0 commit comments