@@ -142,14 +142,8 @@ export class ScmViewComponent implements OnChanges {
142142 case '"' :
143143 return 'tok-str' ;
144144 case '$' : {
145- const refIndex = parseInt ( arg . slice ( 1 ) , 10 ) ;
146-
147- if (
148- ! isNaN ( refIndex ) &&
149- refIndex >= 0 &&
150- refIndex < this . code . symbols . length
151- ) {
152- let symbol = this . code . symbols [ refIndex ] ;
145+ const symbol = this . getSymbol ( arg ) ;
146+ if ( symbol ) {
153147 if ( symbol . startsWith ( 'g.' ) || symbol . startsWith ( 'l.' ) ) {
154148 return 'tok-var' ;
155149 }
@@ -241,19 +235,18 @@ export class ScmViewComponent implements OnChanges {
241235
242236 if ( this . isRef ( i ) && typeof lineOffset === 'number' ) {
243237 const labelId = `label-${ this . code . base + lineOffset } ` ;
238+ let text = this . escapeHtml ( this . formatLabel ( lineOffset ) ) ;
239+ let title = `Click to view Xrefs for ${ text } ` ;
240+ let href = this . escapeAttribute (
241+ this . toCurrentHref ( { fragment : labelId } ) ,
242+ ) ;
243+ let id = this . escapeAttribute ( labelId ) ;
244+ let classes = 'tok-label tok-ref identifier' ;
244245 parts . push (
245- `<a href="${ this . escapeAttribute (
246- this . toCurrentHref ( { fragment : labelId } ) ,
247- ) } " id="${ this . escapeAttribute ( labelId ) } " class="tok-label tok-ref identifier">${ this . escapeHtml (
248- this . formatLabel ( lineOffset ) ,
249- ) } </a>`,
246+ `<a title="${ title } " href="${ href } " id="${ id } " class="${ classes } ">${ text } </a>` ,
250247 ) ;
251248 }
252249
253- // if (this.isUnreachableInstruction(i)) {
254- // parts.push('<div class="text-muted pt-3 pl-5">// unreachable</div>');
255- // }
256-
257250 const activeClass =
258251 this . activeFragment === this . getLineNumberAnchorId ( i ) ? ' active' : '' ;
259252 parts . push ( `<div class="line-row${ activeClass } ">` ) ;
@@ -348,22 +341,32 @@ export class ScmViewComponent implements OnChanges {
348341 ) } </a>`;
349342 }
350343
344+ let symbol = this . getSymbol ( arg ) ;
345+ if ( symbol ) {
346+ let escapedSymbol = this . escapeAttribute ( symbol ) ;
347+ return `<span title="Click to copy ${ symbol } to clipboard" data-copy-text="${ escapedSymbol } " class="tok ${ this . getClass ( arg ) } ">${ this . escapeHtml ( display ) } </span>` ;
348+ }
349+
351350 return `<span class="tok ${ this . getClass ( arg ) } ">${ this . escapeHtml ( display ) } </span>` ;
352351 }
353352
354- private overlayValue ( arg : number | string ) : string {
355- let resolved : number | string = arg ;
356- if ( typeof arg === 'string' && arg . startsWith ( '$' ) ) {
357- const refIndex = Number . parseInt ( arg . slice ( 1 ) , 10 ) ;
358- if (
359- ! Number . isNaN ( refIndex ) &&
360- refIndex >= 0 &&
361- refIndex < this . code . symbols . length
362- ) {
363- resolved = this . code . symbols [ refIndex ] ;
364- }
353+ private getSymbol ( arg : number | string ) : string | null {
354+ if ( typeof arg !== 'string' || ! arg . startsWith ( '$' ) ) {
355+ return null ;
365356 }
357+ const refIndex = Number . parseInt ( arg . slice ( 1 ) , 10 ) ;
358+ if (
359+ Number . isNaN ( refIndex ) ||
360+ refIndex < 0 ||
361+ refIndex >= this . code . symbols . length
362+ ) {
363+ return null ;
364+ }
365+ return this . code . symbols [ refIndex ] ?? null ;
366+ }
366367
368+ private overlayValue ( arg : number | string ) : string {
369+ const resolved = this . getSymbol ( arg ) ?? arg ;
367370 const value = String ( resolved ) ;
368371 return this . overlay [ value ] ?? this . defaultOverlay ( value ) ;
369372 }
0 commit comments