From 26d925bf02f49da45361d4323f64ca2a319755f5 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Thu, 12 Dec 2024 12:03:24 +0100 Subject: [PATCH] Some keyboard shortcuts doesn't work on macOS #663 --- packages/home/tabs-store.tsx | 23 +++++++++++++++++-- packages/main/menu.ts | 16 ++++++------- .../features/page/PagesNavigation.tsx | 5 ++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/home/tabs-store.tsx b/packages/home/tabs-store.tsx index 2d90ea9d..ca0acbc4 100644 --- a/packages/home/tabs-store.tsx +++ b/packages/home/tabs-store.tsx @@ -647,13 +647,32 @@ export class ProjectEditorTab implements IHomeTab { !(event.target instanceof HTMLInputElement) && !(event.target instanceof HTMLTextAreaElement) ) { - if (event.ctrlKey) { - if (event.key == "x") { + if ( + (event.ctrlKey || event.metaKey) && + !event.shiftKey && + !event.altKey + ) { + if (event.key == "z") { + undo(); + } else if (event.key == "y") { + redo(); + } else if (event.key == "x") { cut(); } else if (event.key == "c") { copy(); } else if (event.key == "v") { paste(); + } else if (event.key == "a") { + selectAll(); + } + } else if ( + !event.ctrlKey && + !event.metaKey && + !event.shiftKey && + !event.altKey + ) { + if (event.key == "Backspace" || event.key == "Delete") { + deleteSelection(); } } } diff --git a/packages/main/menu.ts b/packages/main/menu.ts index c9978aec..712cb4c6 100644 --- a/packages/main/menu.ts +++ b/packages/main/menu.ts @@ -471,7 +471,7 @@ function buildEditMenu(win: IWindow | undefined) { id: "undo", label: "Undo", accelerator: "CmdOrCtrl+Z", - role: isMacOs() ? "undo" : undefined, + role: "undo", click: function (item, focusedWindow) { if (focusedWindow) { const win = findWindowByBrowserWindow(focusedWindow); @@ -488,7 +488,7 @@ function buildEditMenu(win: IWindow | undefined) { id: "redo", label: "Redo", accelerator: "CmdOrCtrl+Y", - role: isMacOs() ? "redo" : undefined, + role: "redo", click: function (item, focusedWindow) { if (focusedWindow) { const win = findWindowByBrowserWindow(focusedWindow); @@ -507,7 +507,7 @@ function buildEditMenu(win: IWindow | undefined) { { label: "Cut", accelerator: "CmdOrCtrl+X", - role: isMacOs() ? "cut" : undefined, + role: "cut", click: function (item) { if (win) { win.browserWindow.webContents.send("cut"); @@ -517,7 +517,7 @@ function buildEditMenu(win: IWindow | undefined) { { label: "Copy", accelerator: "CmdOrCtrl+C", - role: isMacOs() ? "copy" : undefined, + role: "copy", click: function (item) { if (win) { win.browserWindow.webContents.send("copy"); @@ -527,7 +527,7 @@ function buildEditMenu(win: IWindow | undefined) { { label: "Paste", accelerator: "CmdOrCtrl+V", - role: isMacOs() ? "paste" : undefined, + role: "paste", click: function (item) { if (win) { win.browserWindow.webContents.send("paste"); @@ -537,7 +537,7 @@ function buildEditMenu(win: IWindow | undefined) { { label: "Delete", accelerator: "Delete", - role: isMacOs() ? "delete" : undefined, + role: "delete", click: function (item) { if (win) { win.browserWindow.webContents.send("delete"); @@ -549,8 +549,8 @@ function buildEditMenu(win: IWindow | undefined) { }, { label: "Select All", - accelerator: isMacOs() ? "CmdOrCtrl+A" : undefined, - role: isMacOs() ? "selectAll" : undefined, + accelerator: "CmdOrCtrl+A", + role: "selectAll", click: function (item) { if (win) { win.browserWindow.webContents.send("select-all"); diff --git a/packages/project-editor/features/page/PagesNavigation.tsx b/packages/project-editor/features/page/PagesNavigation.tsx index 80703e4c..e03da290 100644 --- a/packages/project-editor/features/page/PagesNavigation.tsx +++ b/packages/project-editor/features/page/PagesNavigation.tsx @@ -168,6 +168,11 @@ export const PageStructure = observer( deleteSelection() { this.treeAdapter!.deleteSelection(); } + selectAll() { + this.treeAdapter!.selectItems( + this.treeAdapter!.allRows.map(row => row.item) + ); + } onFocus = () => { this.context.navigationStore.setSelectedPanel(this); };