Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve key binding rendering #10801

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,28 @@ export class KeybindingRegistry {
* @param asciiOnly if `true`, no special characters will be substituted into the string returned. Ensures correct keyboard shortcuts in Electron menus.
*/
acceleratorForKeyCode(keyCode: KeyCode, separator: string = ' ', asciiOnly = false): string {
return this.componentsForKeyCode(keyCode, asciiOnly).join(separator);
}

componentsForKeyCode(keyCode: KeyCode, asciiOnly = false): string[] {
const keyCodeResult = [];
const useSymbols = isOSX && !asciiOnly;
if (keyCode.meta && isOSX) {
keyCodeResult.push('Cmd');
keyCodeResult.push(useSymbols ? '⌘' : 'Cmd');
}
if (keyCode.ctrl) {
keyCodeResult.push('Ctrl');
keyCodeResult.push(useSymbols ? '⌃' : 'Ctrl');
}
if (keyCode.alt) {
keyCodeResult.push('Alt');
keyCodeResult.push(useSymbols ? '⌥' : 'Alt');
}
if (keyCode.shift) {
keyCodeResult.push('Shift');
keyCodeResult.push(useSymbols ? '⇧' : 'Shift');
}
if (keyCode.key) {
keyCodeResult.push(this.acceleratorForKey(keyCode.key, asciiOnly));
}
return keyCodeResult.join(separator);
return keyCodeResult;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/browser/keyboard/keyboard-layout-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,18 @@ export class KeyboardLayoutService {
getKeyboardCharacter(key: Key): string {
const layout = this.currentLayout;
if (layout) {
const value = layout.code2Character[key.code];
if (value && value.replace(/[\n\r\t]/g, '')) {
const value = layout.code2Character[key.code]?.trim();
// Special cases from native keymap
if (value === '\u001b') {
return 'escape';
}
if (value === '\u007f') {
return 'delete';
}
if (value === '\u0008') {
return 'backspace';
}
if (value?.replace(/[\n\r\t]/g, '')) {
return value;
}
}
Expand Down
Loading