@@ -21,6 +21,21 @@ export interface GetLogicalLineTextFromTouchPointArgs {
2121 terminal : TerminalLikeForLongPressCopy ;
2222}
2323
24+ function getRenderedTextBounds ( rowElement : HTMLElement ) : { left : number ; right : number } | null {
25+ const spanRects = Array . from ( rowElement . querySelectorAll ( "span" ) )
26+ . map ( ( span ) => span . getBoundingClientRect ( ) )
27+ . filter ( ( rect ) => rect . width > 0 && rect . height > 0 ) ;
28+
29+ if ( spanRects . length === 0 ) {
30+ return null ;
31+ }
32+
33+ return {
34+ left : Math . min ( ...spanRects . map ( ( rect ) => rect . left ) ) ,
35+ right : Math . max ( ...spanRects . map ( ( rect ) => rect . right ) ) ,
36+ } ;
37+ }
38+
2439function getVisualRowIndexFromTouchPoint (
2540 rowsElement : HTMLElement ,
2641 clientX : number ,
@@ -40,8 +55,16 @@ function getVisualRowIndexFromTouchPoint(
4055 ( child ) : child is HTMLElement => child instanceof HTMLElement
4156 ) ;
4257 for ( let index = 0 ; index < rowElements . length ; index += 1 ) {
43- const rowRect = rowElements [ index ] . getBoundingClientRect ( ) ;
44- if ( clientY >= rowRect . top && clientY <= rowRect . bottom ) {
58+ const rowElement = rowElements [ index ] ;
59+ const rowRect = rowElement . getBoundingClientRect ( ) ;
60+ if ( clientY < rowRect . top || clientY > rowRect . bottom ) {
61+ continue ;
62+ }
63+
64+ const renderedTextBounds = getRenderedTextBounds ( rowElement ) ;
65+ const left = renderedTextBounds ?. left ?? rowRect . left ;
66+ const right = renderedTextBounds ?. right ?? rowRect . right ;
67+ if ( clientX >= left && clientX <= right ) {
4568 return index ;
4669 }
4770 }
0 commit comments