@@ -2,7 +2,9 @@ import { isMacPlatform } from "../../lib/utils";
22import { SELECTION_MULTI_CLICK_INTERVAL_MS } from "../../lib/selectionActions" ;
33import { collectWrappedTerminalLinkLine , extractTerminalLinks } from "../../terminal-links" ;
44import {
5+ GHOSTTY_CELL_WIDE ,
56 GhosttyTerminalCore ,
7+ type GhosttyCell ,
68 type GhosttyScrollbar ,
79 type GhosttySnapshot ,
810 type GhosttyTheme ,
@@ -201,15 +203,23 @@ function terminalGridCellAt(options: {
201203 } ;
202204}
203205
206+ function terminalCellText ( cell : GhosttyCell ) : string {
207+ if ( cell . wide === GHOSTTY_CELL_WIDE . spacerTail || cell . wide === GHOSTTY_CELL_WIDE . spacerHead ) {
208+ return "" ;
209+ }
210+ return cell . text || " " ;
211+ }
212+
204213function terminalRowText ( row : GhosttySnapshot [ "rowData" ] [ number ] , trimRight : boolean ) : string {
205- const text = row . cells . map ( ( cell ) => cell . text || " " ) . join ( "" ) ;
214+ const text = row . cells . map ( terminalCellText ) . join ( "" ) ;
206215 return trimRight ? text . trimEnd ( ) : text ;
207216}
208217
209218function terminalColumnOffset ( row : GhosttySnapshot [ "rowData" ] [ number ] , column : number ) : number {
210219 let offset = 0 ;
211220 for ( let cellIndex = 0 ; cellIndex < column ; cellIndex += 1 ) {
212- offset += row . cells [ cellIndex ] ?. text . length || 1 ;
221+ const cell = row . cells [ cellIndex ] ;
222+ offset += cell ? terminalCellText ( cell ) . length : 1 ;
213223 }
214224 return offset ;
215225}
@@ -265,7 +275,8 @@ export function terminalLinkAtPositionWithRange(
265275 const lastSegment = wrappedLine . segments . at ( - 1 ) ;
266276 const lastRow = lastSegment ? rows [ lastSegment . bufferLineNumber - 1 ] : undefined ;
267277 const continuesBelowViewport = lastRow !== undefined && lastRow . wrapsToNext ;
268- const offset = segment . startIndex + terminalColumnOffset ( row , column ) ;
278+ const hitColumn = row . cells [ column ] ?. wide === GHOSTTY_CELL_WIDE . spacerTail ? column - 1 : column ;
279+ const offset = segment . startIndex + terminalColumnOffset ( row , hitColumn ) ;
269280 for ( const match of extractTerminalLinks ( wrappedLine . text ) ) {
270281 if ( offset >= match . start && offset < match . end ) {
271282 if ( match . end === wrappedLine . text . length && continuesBelowViewport ) return null ;
@@ -278,6 +289,7 @@ export function terminalLinkAtPositionWithRange(
278289 const startRow = startSegment ? rows [ startSegment . bufferLineNumber - 1 ] : undefined ;
279290 const endRow = endSegment ? rows [ endSegment . bufferLineNumber - 1 ] : undefined ;
280291 if ( ! startSegment || ! endSegment || ! startRow || ! endRow ) return null ;
292+ const endColumn = terminalColumnAtOffset ( endRow , match . end - 1 - endSegment . startIndex ) ;
281293 return {
282294 text : match . text ,
283295 range : {
@@ -286,7 +298,10 @@ export function terminalLinkAtPositionWithRange(
286298 y : startSegment . bufferLineNumber - 1 ,
287299 } ,
288300 end : {
289- x : terminalColumnAtOffset ( endRow , match . end - 1 - endSegment . startIndex ) ,
301+ x :
302+ endRow . cells [ endColumn + 1 ] ?. wide === GHOSTTY_CELL_WIDE . spacerTail
303+ ? endColumn + 1
304+ : endColumn ,
290305 y : endSegment . bufferLineNumber - 1 ,
291306 } ,
292307 } ,
0 commit comments