未验证 提交 09afa054 编写于 作者: S SteVen Batten 提交者: GitHub

fix undo, redo, selectAll on macOS (#60040)

上级 6a940ef1
...@@ -25,6 +25,11 @@ import { IStateService } from 'vs/platform/state/common/state'; ...@@ -25,6 +25,11 @@ import { IStateService } from 'vs/platform/state/common/state';
const telemetryFrom = 'menu'; const telemetryFrom = 'menu';
interface IMenuItemClickHandler {
inDevTools: (contents: Electron.WebContents) => void;
inNoWindow: () => void;
}
export class Menubar { export class Menubar {
private static readonly MAX_MENU_RECENT_ENTRIES = 10; private static readonly MAX_MENU_RECENT_ENTRIES = 10;
...@@ -634,8 +639,8 @@ export class Menubar { ...@@ -634,8 +639,8 @@ export class Menubar {
commandId = arg2[0]; commandId = arg2[0];
} }
// Add role for special case menu items
if (isMacintosh) { if (isMacintosh) {
// Add role for special case menu items
if (commandId === 'editor.action.clipboardCutAction') { if (commandId === 'editor.action.clipboardCutAction') {
options['role'] = 'cut'; options['role'] = 'cut';
} else if (commandId === 'editor.action.clipboardCopyAction') { } else if (commandId === 'editor.action.clipboardCopyAction') {
...@@ -643,11 +648,47 @@ export class Menubar { ...@@ -643,11 +648,47 @@ export class Menubar {
} else if (commandId === 'editor.action.clipboardPasteAction') { } else if (commandId === 'editor.action.clipboardPasteAction') {
options['role'] = 'paste'; options['role'] = 'paste';
} }
// Add context aware click handlers for special case menu items
if (commandId === 'undo') {
options.click = this.makeContextAwareClickHandler(click, {
inDevTools: devTools => devTools.undo(),
inNoWindow: () => Menu.sendActionToFirstResponder('undo:')
});
} else if (commandId === 'redo') {
options.click = this.makeContextAwareClickHandler(click, {
inDevTools: devTools => devTools.redo(),
inNoWindow: () => Menu.sendActionToFirstResponder('redo:')
});
} else if (commandId === 'editor.action.selectAll') {
options.click = this.makeContextAwareClickHandler(click, {
inDevTools: devTools => devTools.selectAll(),
inNoWindow: () => Menu.sendActionToFirstResponder('selectAll:')
});
}
} }
return new MenuItem(this.withKeybinding(commandId, options)); return new MenuItem(this.withKeybinding(commandId, options));
} }
private makeContextAwareClickHandler(click: () => void, contextSpecificHandlers: IMenuItemClickHandler): () => void {
return () => {
// No Active Window
const activeWindow = this.windowsMainService.getFocusedWindow();
if (!activeWindow) {
return contextSpecificHandlers.inNoWindow();
}
// DevTools focused
if (activeWindow.win.webContents.isDevToolsFocused()) {
return contextSpecificHandlers.inDevTools(activeWindow.win.webContents.devToolsWebContents);
}
// Finally execute command in Window
click();
};
}
private runActionInRenderer(id: string): void { private runActionInRenderer(id: string): void {
// We make sure to not run actions when the window has no focus, this helps // We make sure to not run actions when the window has no focus, this helps
// for https://github.com/Microsoft/vscode/issues/25907 and specifically for // for https://github.com/Microsoft/vscode/issues/25907 and specifically for
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册