Skip to content

Commit bbe2fdb

Browse files
author
Benjamin Pasero
committed
1 parent 3a6cd57 commit bbe2fdb

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/vs/base/common/labels.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export function mnemonicMenuLabel(label: string, forceDisableMnemonics?: boolean
366366

367367
/**
368368
* Handles mnemonics for buttons. Depending on OS:
369-
* - Windows: Supported via & character (replace && with &)
369+
* - Windows: Supported via & character (replace && with & and & with && for escaping)
370370
* - Linux: Supported via _ character (replace && with _)
371371
* - macOS: Unsupported (replace && with empty string)
372372
*/
@@ -375,7 +375,11 @@ export function mnemonicButtonLabel(label: string): string {
375375
return label.replace(/\(&&\w\)|&&/g, '');
376376
}
377377

378-
return label.replace(/&&/g, isWindows ? '&' : '_');
378+
if (isWindows) {
379+
return label.replace(/&&|&/g, m => m === '&' ? '&&' : '&');
380+
}
381+
382+
return label.replace(/&&/g, '_');
379383
}
380384

381385
export function unmnemonicLabel(label: string): string {

src/vs/base/test/common/labels.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,19 @@ suite('Labels', () => {
164164
assert.equal(labels.getBaseLabel('c:\\some\\folder\\file.txt'), 'file.txt');
165165
assert.equal(labels.getBaseLabel('c:\\some\\folder'), 'folder');
166166
});
167+
168+
test('mnemonicButtonLabel', () => {
169+
assert.equal(labels.mnemonicButtonLabel('Hello World'), 'Hello World');
170+
assert.equal(labels.mnemonicButtonLabel(''), '');
171+
if (platform.isWindows) {
172+
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello && World');
173+
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do &not Save && Continue');
174+
} else if (platform.isMacintosh) {
175+
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
176+
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do not Save & Continue');
177+
} else {
178+
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
179+
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do _not Save & Continue');
180+
}
181+
});
167182
});

0 commit comments

Comments
 (0)