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

GH-8654: Fix SelectAll/Copy/Paste Keyboard Shortcuts are not working within DevTools and native input and file dialogs for macOS #8943

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
MAIN_MENU_BAR, MenuModelRegistry, MenuPath, MenuNode
} from '../../common';
import { Keybinding } from '../../common/keybinding';
import { PreferenceService, KeybindingRegistry } from '../../browser';
import { PreferenceService, KeybindingRegistry, CommonCommands } from '../../browser';
import { ContextKeyService } from '../../browser/context-key-service';
import debounce = require('lodash.debounce');
import { ContextMenuContext } from '../../browser/menu/context-menu-context';
Expand All @@ -39,6 +39,20 @@ export interface ElectronMenuOptions {
readonly showDisabled?: boolean;
}

/**
* Define the action of the menu item, when specified the `click` property will
* be ignored. See [roles](https://www.electronjs.org/docs/api/menu-item#roles).
*/
export type ElectronMenuItemRole = ('undo' | 'redo' | 'cut' | 'copy' | 'paste' |
'pasteAndMatchStyle' | 'delete' | 'selectAll' | 'reload' | 'forceReload' |
'toggleDevTools' | 'resetZoom' | 'zoomIn' | 'zoomOut' | 'togglefullscreen' |
'window' | 'minimize' | 'close' | 'help' | 'about' |
'services' | 'hide' | 'hideOthers' | 'unhide' | 'quit' |
'startSpeaking' | 'stopSpeaking' | 'zoom' | 'front' | 'appMenu' |
'fileMenu' | 'editMenu' | 'viewMenu' | 'recentDocuments' | 'toggleTabBar' |
'selectNextTab' | 'selectPreviousTab' | 'mergeAllWindows' | 'clearRecentDocuments' |
'moveTabToNewWindow' | 'windowMenu');

@injectable()
export class ElectronMainMenuFactory {

Expand Down Expand Up @@ -164,16 +178,26 @@ export class ElectronMainMenuFactory {
accelerator = this.acceleratorFor(binding);
}

items.push({
const menuItem = {
id: node.id,
label: node.label,
type: this.commandRegistry.getToggledHandler(commandId, ...args) ? 'checkbox' : 'normal',
checked: this.commandRegistry.isToggled(commandId, ...args),
enabled: true, // https://github.com/eclipse-theia/theia/issues/446
visible: true,
click: () => this.execute(commandId, args),
accelerator
});
accelerator,
click: () => this.execute(commandId, args)
} as Electron.MenuItemConstructorOptions;

if (isOSX) {
const role = this.roleFor(node.id);
if (role) {
menuItem.role = role;
delete menuItem.click;
}
}
items.push(menuItem);

if (this.commandRegistry.getToggledHandler(commandId, ...args)) {
this._toggledCommands.add(commandId);
}
Expand Down Expand Up @@ -206,6 +230,33 @@ export class ElectronMainMenuFactory {
return this.keybindingRegistry.acceleratorForKeyCode(keyCode, '+');
}

protected roleFor(id: string): ElectronMenuItemRole | undefined {
let role: ElectronMenuItemRole | undefined;
switch (id) {
case CommonCommands.UNDO.id:
role = 'undo';
break;
case CommonCommands.REDO.id:
role = 'redo';
break;
case CommonCommands.CUT.id:
role = 'cut';
break;
case CommonCommands.COPY.id:
role = 'copy';
break;
case CommonCommands.PASTE.id:
role = 'paste';
break;
case CommonCommands.SELECT_ALL.id:
role = 'selectAll';
break;
default:
break;
}
return role;
}

protected async execute(command: string, args: any[]): Promise<void> {
try {
// This is workaround for https://github.com/eclipse-theia/theia/issues/446.
Expand Down