Skip to content

Commit 424a2bf

Browse files
committed
refs #106285
1 parent ee5ee9e commit 424a2bf

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/vs/base/browser/ui/menu/menubar.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,25 +532,31 @@ export class MenuBar extends Disposable {
532532
// Update the button label to reflect mnemonics
533533

534534
if (this.options.enableMnemonics) {
535-
let innerHtml = strings.escape(label);
535+
let cleanLabel = strings.escape(label);
536536

537537
// This is global so reset it
538538
MENU_ESCAPED_MNEMONIC_REGEX.lastIndex = 0;
539-
let escMatch = MENU_ESCAPED_MNEMONIC_REGEX.exec(innerHtml);
539+
let escMatch = MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel);
540540

541541
// We can't use negative lookbehind so we match our negative and skip
542542
while (escMatch && escMatch[1]) {
543-
escMatch = MENU_ESCAPED_MNEMONIC_REGEX.exec(innerHtml);
543+
escMatch = MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel);
544544
}
545545

546+
const replaceDoubleEscapes = (str: string) => str.replace(/&&/g, '&');
547+
546548
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();
548557
}
549-
550-
innerHtml = innerHtml.replace(/&amp;&amp;/g, '&amp;');
551-
titleElement.innerHTML = innerHtml;
552558
} else {
553-
titleElement.innerHTML = cleanMenuLabel.replace(/&&/g, '&');
559+
titleElement.innerText = cleanMenuLabel.replace(/&&/g, '&');
554560
}
555561

556562
let mnemonicMatches = MENU_MNEMONIC_REGEX.exec(label);

0 commit comments

Comments
 (0)