@@ -38,6 +38,32 @@ function getTextRect(
3838 return { x, y, width, height } ;
3939}
4040
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+
4167export const uriCellRenderer : InternalCellRenderer < UriCell > = {
4268 getAccessibilityString : c => c . data ?. toString ( ) ?? "" ,
4369 kind : GridCellKind . Uri ,
@@ -82,26 +108,16 @@ export const uriCellRenderer: InternalCellRenderer<UriCell> = {
82108 ctx . fillStyle = isLinky ? theme . linkColor : theme . textDark ;
83109 drawTextCell ( a , txt , cell . contentAlign ) ;
84110 } ,
111+ onSelect : e => {
112+ if ( isOverLinkText ( e ) ) {
113+ e . preventDefault ( ) ;
114+ }
115+ } ,
85116 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 ) ;
103119 if ( didClick ) {
104- cell . onClickUri ( a ) ;
120+ cell . onClickUri ?. ( a ) ;
105121 }
106122 return undefined ;
107123 } ,
0 commit comments