Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix all cmd shortcuts (#1020)

Bogdan Chadkinf91190be40a0
diff --git a/apps/designer/app/canvas/shared/use-shortcuts.ts b/apps/designer/app/canvas/shared/use-shortcuts.ts
index 67c170929a..c8b3f65ad8 100644
--- a/apps/designer/app/canvas/shared/use-shortcuts.ts
+++ b/apps/designer/app/canvas/shared/use-shortcuts.ts
@@ -1,5 +1,4 @@
import { useHotkeys } from "react-hotkeys-hook";
-import store from "immerhin";
import { getComponentMeta } from "@webstudio-is/react-sdk";
import { shortcuts, options } from "~/shared/shortcuts";
import { publish, useSubscribe } from "~/shared/pubsub";
@@ -51,8 +50,6 @@ export const useShortcuts = () => {
const [editingInstanceId, setEditingInstanceId] = useTextEditingInstanceId();
const shortcutHandlerMap = {
- undo: store.undo.bind(store),
- redo: store.redo.bind(store),
preview: togglePreviewMode,
breakpointsMenu: publishOpenBreakpointsMenu,
breakpoint: publishSelectBreakpoint,
@@ -95,10 +92,6 @@ export const useShortcuts = () => {
[setEditingInstanceId]
);
- useHotkeys(shortcuts.undo, shortcutHandlerMap.undo, options, []);
-
- useHotkeys(shortcuts.redo, shortcutHandlerMap.redo, options, []);
-
useHotkeys(shortcuts.preview, shortcutHandlerMap.preview, options, []);
useHotkeys(shortcuts.breakpoint, shortcutHandlerMap.breakpoint, options, []);
diff --git a/apps/designer/app/designer/features/topbar/menu/menu.tsx b/apps/designer/app/designer/features/topbar/menu/menu.tsx
index fc0c7a3e99..e07871276f 100644
--- a/apps/designer/app/designer/features/topbar/menu/menu.tsx
+++ b/apps/designer/app/designer/features/topbar/menu/menu.tsx
@@ -1,4 +1,5 @@
import { useNavigate } from "@remix-run/react";
+import store from "immerhin";
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import {
theme,
@@ -133,27 +134,13 @@ export const Menu = ({ publish }: MenuProps) => {
Dashboard
</DropdownMenuItem>
<DropdownMenuSeparator />
- <DropdownMenuItem
- onSelect={() => {
- publish({
- type: "shortcut",
- payload: { name: "undo" },
- });
- }}
- >
+ <DropdownMenuItem onSelect={() => store.undo()}>
Undo
<DropdownMenuItemRightSlot>
<ShortcutHint value={["cmd", "z"]} />
</DropdownMenuItemRightSlot>
</DropdownMenuItem>
- <DropdownMenuItem
- onSelect={() => {
- publish({
- type: "shortcut",
- payload: { name: "redo" },
- });
- }}
- >
+ <DropdownMenuItem onSelect={() => store.redo()}>
Redo
<DropdownMenuItemRightSlot>
<ShortcutHint value={["shift", "cmd", "z"]} />
diff --git a/apps/designer/app/shared/shortcuts/shortcuts.ts b/apps/designer/app/shared/shortcuts/shortcuts.ts
index 9448044ba9..08ad124356 100644
--- a/apps/designer/app/shared/shortcuts/shortcuts.ts
+++ b/apps/designer/app/shared/shortcuts/shortcuts.ts
@@ -1,16 +1,15 @@
import { Options, useHotkeys } from "react-hotkeys-hook";
+import store from "immerhin";
import { selectedInstanceIdStore } from "../nano-states";
import { zoomIn, zoomOut } from "../nano-states/breakpoints";
import { deleteInstance } from "../instance-utils";
export const shortcuts = {
esc: "esc",
- undo: "cmd+z, ctrl+z",
- redo: "cmd+shift+z, ctrl+shift+z",
- preview: "cmd+shift+p, ctrl+shift+p",
- breakpointsMenu: "cmd+b, ctrl+b",
+ preview: "meta+shift+p, ctrl+shift+p",
+ breakpointsMenu: "meta+b, ctrl+b",
breakpoint: Array.from(new Array(9))
- .map((_, index) => `cmd+${index + 1}, ctrl+${index + 1}`)
+ .map((_, index) => `meta+${index + 1}, ctrl+${index + 1}`)
.join(", "),
} as const;
@@ -19,6 +18,22 @@ export const options: Options = {
};
export const useSharedShortcuts = () => {
+ useHotkeys(
+ // safari use cmd+z to reopen closed tabs so fallback to ctrl
+ "meta+z, ctrl+z",
+ () => store.undo(),
+ { enableOnFormTags: true, enableOnContentEditable: false },
+ []
+ );
+
+ useHotkeys(
+ // safari use cmd+shift+z to close reopened tabs so fallback to ctrl
+ "meta+shift+z, ctrl+shift+z",
+ () => store.redo(),
+ { enableOnFormTags: true, enableOnContentEditable: false },
+ []
+ );
+
useHotkeys(
"backspace, delete",
() => {