@@ -532,25 +532,31 @@ export class MenuBar extends Disposable {
532
532
// Update the button label to reflect mnemonics
533
533
534
534
if ( this . options . enableMnemonics ) {
535
- let innerHtml = strings . escape ( label ) ;
535
+ let cleanLabel = strings . escape ( label ) ;
536
536
537
537
// This is global so reset it
538
538
MENU_ESCAPED_MNEMONIC_REGEX . lastIndex = 0 ;
539
- let escMatch = MENU_ESCAPED_MNEMONIC_REGEX . exec ( innerHtml ) ;
539
+ let escMatch = MENU_ESCAPED_MNEMONIC_REGEX . exec ( cleanLabel ) ;
540
540
541
541
// We can't use negative lookbehind so we match our negative and skip
542
542
while ( escMatch && escMatch [ 1 ] ) {
543
- escMatch = MENU_ESCAPED_MNEMONIC_REGEX . exec ( innerHtml ) ;
543
+ escMatch = MENU_ESCAPED_MNEMONIC_REGEX . exec ( cleanLabel ) ;
544
544
}
545
545
546
+ const replaceDoubleEscapes = ( str : string ) => str . replace ( / & a m p ; & a m p ; / g, '&' ) ;
547
+
546
548
if ( escMatch ) {
547
- innerHtml = `${ innerHtml . substr ( 0 , escMatch . index ) } <mnemonic aria-hidden="true">${ escMatch [ 3 ] } </mnemonic>${ innerHtml . substr ( escMatch . index + escMatch [ 0 ] . length ) } ` ;
549
+ titleElement . innerText = '' ;
550
+ titleElement . append (
551
+ strings . ltrim ( replaceDoubleEscapes ( cleanLabel . substr ( 0 , escMatch . index ) ) , ' ' ) ,
552
+ $ ( 'mnemonic' , { 'aria-hidden' : 'true' } , escMatch [ 3 ] ) ,
553
+ strings . rtrim ( replaceDoubleEscapes ( cleanLabel . substr ( escMatch . index + escMatch [ 0 ] . length ) ) , ' ' )
554
+ ) ;
555
+ } else {
556
+ titleElement . innerText = replaceDoubleEscapes ( cleanLabel ) . trim ( ) ;
548
557
}
549
-
550
- innerHtml = innerHtml . replace ( / & a m p ; & a m p ; / g, '&' ) ;
551
- titleElement . innerHTML = innerHtml ;
552
558
} else {
553
- titleElement . innerHTML = cleanMenuLabel . replace ( / & & / g, '&' ) ;
559
+ titleElement . innerText = cleanMenuLabel . replace ( / & & / g, '&' ) ;
554
560
}
555
561
556
562
let mnemonicMatches = MENU_MNEMONIC_REGEX . exec ( label ) ;
0 commit comments