提交 bbe2fdb2 编写于 作者: B Benjamin Pasero

fix #64999

上级 3a6cd578
......@@ -366,7 +366,7 @@ export function mnemonicMenuLabel(label: string, forceDisableMnemonics?: boolean
/**
* Handles mnemonics for buttons. Depending on OS:
* - Windows: Supported via & character (replace && with &)
* - Windows: Supported via & character (replace && with & and & with && for escaping)
* - Linux: Supported via _ character (replace && with _)
* - macOS: Unsupported (replace && with empty string)
*/
......@@ -375,7 +375,11 @@ export function mnemonicButtonLabel(label: string): string {
return label.replace(/\(&&\w\)|&&/g, '');
}
return label.replace(/&&/g, isWindows ? '&' : '_');
if (isWindows) {
return label.replace(/&&|&/g, m => m === '&' ? '&&' : '&');
}
return label.replace(/&&/g, '_');
}
export function unmnemonicLabel(label: string): string {
......
......@@ -164,4 +164,19 @@ suite('Labels', () => {
assert.equal(labels.getBaseLabel('c:\\some\\folder\\file.txt'), 'file.txt');
assert.equal(labels.getBaseLabel('c:\\some\\folder'), 'folder');
});
test('mnemonicButtonLabel', () => {
assert.equal(labels.mnemonicButtonLabel('Hello World'), 'Hello World');
assert.equal(labels.mnemonicButtonLabel(''), '');
if (platform.isWindows) {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello && World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do &not Save && Continue');
} else if (platform.isMacintosh) {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do not Save & Continue');
} else {
assert.equal(labels.mnemonicButtonLabel('Hello & World'), 'Hello & World');
assert.equal(labels.mnemonicButtonLabel('Do &&not Save & Continue'), 'Do _not Save & Continue');
}
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册