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.

feat: Shortcuts help dialog (#5495)

Oleg Isonen8b63e5dffc38
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsx
index 11aefceaa7..3e58004797 100644
--- a/apps/builder/app/builder/builder.tsx
+++ b/apps/builder/app/builder/builder.tsx
@@ -62,6 +62,7 @@ import { CommandPanel } from "./features/command-panel";
import { DeleteUnusedTokensDialog } from "~/builder/shared/style-source-utils";
import { DeleteUnusedDataVariablesDialog } from "~/builder/shared/data-variable-utils";
import { DeleteUnusedCssVariablesDialog } from "~/builder/shared/css-variable-utils";
+import { KeyboardShortcutsDialog } from "./features/keyboard-shortcuts-dialog";
import {
initCopyPaste,
@@ -445,6 +446,7 @@ export const Builder = ({
<DeleteUnusedTokensDialog />
<DeleteUnusedDataVariablesDialog />
<DeleteUnusedCssVariablesDialog />
+ <KeyboardShortcutsDialog />
<RemoteDialog />
</div>
</TooltipProvider>
diff --git a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/index.ts b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/index.ts
new file mode 100644
index 0000000000..a9592a6916
--- /dev/null
+++ b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/index.ts
@@ -0,0 +1,4 @@
+export {
+ KeyboardShortcutsDialog,
+ openKeyboardShortcutsDialog,
+} from "./keyboard-shortcuts-dialog";
diff --git a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx
new file mode 100644
index 0000000000..87a5eb727a
--- /dev/null
+++ b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx
@@ -0,0 +1,19 @@
+import type { Meta } from "@storybook/react";
+import { useEffect } from "react";
+import { subscribeCommands } from "~/builder/shared/commands";
+import {
+ KeyboardShortcutsDialog,
+ openKeyboardShortcutsDialog,
+} from "./keyboard-shortcuts-dialog";
+
+// Initialize commands
+subscribeCommands();
+
+export default {
+ title: "Keyboard Shortcuts Dialog",
+} satisfies Meta;
+
+export const KeyboardShortcuts = () => {
+ useEffect(openKeyboardShortcutsDialog, []);
+ return <KeyboardShortcutsDialog />;
+};
diff --git a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx
new file mode 100644
index 0000000000..0321d50caa
--- /dev/null
+++ b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx
@@ -0,0 +1,268 @@
+import { useStore } from "@nanostores/react";
+import {
+ Dialog,
+ DialogTitle,
+ DialogContent,
+ Grid,
+ Text,
+ Kbd,
+ filterHotkeyByOs,
+ ScrollArea,
+ theme,
+ Box,
+} from "@webstudio-is/design-system";
+import { atom } from "nanostores";
+import { $commandMetas } from "~/shared/commands-emitter";
+
+const $isKeyboardShortcutsOpen = atom(false);
+
+export const openKeyboardShortcutsDialog = () => {
+ $isKeyboardShortcutsOpen.set(true);
+};
+
+// Additional shortcuts not in commands system but should be shown
+const additionalShortcuts = [
+ {
+ name: "copy",
+ label: "Copy",
+ description: "Copy selected instance",
+ category: "Navigator",
+ defaultHotkeys: ["meta+c", "ctrl+c"],
+ },
+ {
+ name: "cut",
+ label: "Cut",
+ description: "Cut selected instance",
+ category: "Navigator",
+ defaultHotkeys: ["meta+x", "ctrl+x"],
+ },
+ {
+ name: "paste",
+ label: "Paste",
+ description: "Paste copied instance",
+ category: "Navigator",
+ defaultHotkeys: ["meta+v", "ctrl+v"],
+ },
+ {
+ name: "expandNavigatorItem",
+ label: "Expand Navigator item",
+ description: "Expand navigator item",
+ category: "Navigator",
+ defaultHotkeys: ["→"],
+ },
+ {
+ name: "collapseNavigatorItem",
+ label: "Collapse Navigator item",
+ description: "Collapse navigator item",
+ category: "Navigator",
+ defaultHotkeys: ["←"],
+ },
+ {
+ name: "switchBreakpoint",
+ label: "Switch breakpoints",
+ description: "Switch to breakpoint by number (1-9)",
+ category: "Top bar",
+ defaultHotkeys: ["1-9"],
+ },
+];
+
+export const KeyboardShortcutsDialog = () => {
+ const isOpen = useStore($isKeyboardShortcutsOpen);
+ const commandMetas = useStore($commandMetas);
+
+ // Filter commands that have hotkeys and are not hidden
+ const commandsWithHotkeys = Array.from(commandMetas.values()).filter(
+ (command) =>
+ command.defaultHotkeys &&
+ command.defaultHotkeys.length > 0 &&
+ !command.hidden
+ );
+
+ // Combine with additional shortcuts
+ const allShortcuts = [...commandsWithHotkeys, ...additionalShortcuts];
+
+ // Extract valid command names as a type
+ type ValidCommandName = (typeof allShortcuts)[number]["name"];
+
+ // Group filtered commands by category
+ const groupedCommands = allShortcuts.reduce<
+ Record<string, Array<(typeof allShortcuts)[number]>>
+ >((acc, command) => {
+ const category = command.category ?? "Other";
+ if (!acc[category]) {
+ acc[category] = [];
+ }
+ acc[category].push(command);
+ return acc;
+ }, {});
+
+ // Define popularity order for shortcuts within each category
+ const shortcutOrder: Record<string, ValidCommandName[]> = {
+ General: [
+ "cancelCurrentDrag",
+ "openCommandPanel",
+ "openPublishDialog",
+ "openExportDialog",
+ "openKeyboardShortcuts",
+ ],
+ "Top bar": ["toggleDesignMode", "togglePreviewMode", "toggleContentMode"],
+ Navigator: [
+ "copy",
+ "cut",
+ "paste",
+ "duplicateInstance",
+ "expandNavigatorItem",
+ "collapseNavigatorItem",
+ ],
+ Panels: [
+ "toggleComponentsPanel",
+ "toggleNavigatorPanel",
+ "openStylePanel",
+ "openSettingsPanel",
+ ],
+
+ "Style panel": [
+ "focusStyleSources",
+ "toggleStylePanelFocusMode",
+ "toggleStylePanelAdvancedMode",
+ ],
+ };
+
+ // Extract valid category names as a type
+ type ValidCategory = keyof typeof groupedCommands;
+
+ // Sort shortcuts within each category by popularity
+ Object.keys(groupedCommands).forEach((category) => {
+ const order = shortcutOrder[category] || [];
+ groupedCommands[category].sort((a, b) => {
+ const aIndex = order.indexOf(a.name);
+ const bIndex = order.indexOf(b.name);
+ // If both are in the order list, sort by their position
+ if (aIndex !== -1 && bIndex !== -1) {
+ return aIndex - bIndex;
+ }
+ // If only one is in the order list, prioritize it
+ if (aIndex !== -1) {
+ return -1;
+ }
+ if (bIndex !== -1) {
+ return 1;
+ }
+ // If neither is in the order list, maintain original order
+ return 0;
+ });
+ });
+
+ // Define category order by popularity
+ const categoryOrder: ValidCategory[] = [
+ "General",
+ "Top bar",
+ "Navigator",
+ "Panels",
+ "Style panel",
+ ];
+
+ // Sort categories by popularity
+ const sortedCategories = Object.keys(groupedCommands).sort((a, b) => {
+ const aIndex = categoryOrder.indexOf(a);
+ const bIndex = categoryOrder.indexOf(b);
+ // If both are in the order list, sort by their position
+ if (aIndex !== -1 && bIndex !== -1) {
+ return aIndex - bIndex;
+ }
+ // If only one is in the order list, prioritize it
+ if (aIndex !== -1) {
+ return -1;
+ }
+ if (bIndex !== -1) {
+ return 1;
+ }
+ // If neither is in the order list, maintain original order
+ return 0;
+ });
+
+ return (
+ <Dialog
+ open={isOpen}
+ onOpenChange={(open) => $isKeyboardShortcutsOpen.set(open)}
+ >
+ <DialogContent
+ css={{
+ width: 700,
+ display: "flex",
+ flexDirection: "column",
+ }}
+ >
+ <DialogTitle>Keyboard shortcuts</DialogTitle>
+ <ScrollArea>
+ <Grid columns={2} gap={3} css={{ padding: theme.panel.padding }}>
+ {sortedCategories.map((category) => {
+ const categoryCommands = groupedCommands[category];
+ return (
+ <Box key={category}>
+ <Text
+ variant="titles"
+ color="main"
+ css={{ mb: theme.spacing[5] }}
+ >
+ {category}
+ </Text>
+ <Grid
+ gap={3}
+ align="center"
+ css={{ gridTemplateColumns: "10ch 1fr" }}
+ >
+ {categoryCommands.map((command) => {
+ const hotkey = command.defaultHotkeys
+ ? filterHotkeyByOs(command.defaultHotkeys)
+ : undefined;
+
+ if (!hotkey) {
+ return;
+ }
+
+ return (
+ <>
+ <Box
+ css={{
+ textAlign: "right",
+ }}
+ >
+ <Box
+ as="span"
+ css={{
+ paddingInline: 4,
+ border: `1px solid ${theme.colors.borderNeutral}`,
+ borderRadius: theme.borderRadius[2],
+ }}
+ >
+ <Kbd
+ key={`${command.name}-kbd`}
+ value={hotkey.split("+") as string[]}
+ color="moreSubtle"
+ />
+ </Box>
+ </Box>
+ <Text
+ key={`${command.name}-text`}
+ variant="regular"
+ color="subtle"
+ >
+ {("description" in command &&
+ command.description) ||
+ command.label ||
+ command.name}
+ </Text>
+ </>
+ );
+ })}
+ </Grid>
+ </Box>
+ );
+ })}
+ </Grid>
+ </ScrollArea>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/apps/builder/app/builder/features/topbar/menu/menu.tsx b/apps/builder/app/builder/features/topbar/menu/menu.tsx
index ca5957c3c0..8d0b6102a5 100644
--- a/apps/builder/app/builder/features/topbar/menu/menu.tsx
+++ b/apps/builder/app/builder/features/topbar/menu/menu.tsx
@@ -253,14 +253,11 @@ export const Menu = () => {
</DropdownMenuItem>
)}
- <DropdownMenuItem
- onSelect={() => {
- window.open(
- "https://docs.webstudio.is/university/foundations/shortcuts"
- );
- }}
- >
- Keyboard shortcuts
+ <DropdownMenuItem onSelect={() => emitCommand("openKeyboardShortcuts")}>
+ Keyboard Shortcuts
+ <DropdownMenuItemRightSlot>
+ <Kbd value={["shift", "?"]} />
+ </DropdownMenuItemRightSlot>
</DropdownMenuItem>
<DropdownMenuSub>
diff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.ts
index 6995f6d522..1ed2c998d9 100644
--- a/apps/builder/app/builder/shared/commands.ts
+++ b/apps/builder/app/builder/shared/commands.ts
@@ -60,6 +60,7 @@ import { isSyncIdle } from "./sync/sync-server";
import { openDeleteUnusedTokensDialog } from "~/builder/shared/style-source-utils";
import { openDeleteUnusedDataVariablesDialog } from "~/builder/shared/data-variable-utils";
import { openDeleteUnusedCssVariablesDialog } from "~/builder/shared/css-variable-utils";
+import { openKeyboardShortcutsDialog } from "~/builder/features/keyboard-shortcuts-dialog";
export const $styleSourceInputElement = atom<HTMLInputElement | undefined>();
@@ -327,7 +328,10 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "cancelCurrentDrag",
+ label: "Deselect",
+ description: "Cancel drag or deselect",
hidden: true,
+ category: "General",
defaultHotkeys: ["escape"],
// radix check event.defaultPrevented before invoking callbacks
preventDefault: false,
@@ -338,6 +342,7 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "clickCanvas",
+ description: "Click on canvas",
hidden: true,
handler: () => {
$breakpointsMenuView.set(undefined);
@@ -349,6 +354,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "togglePreviewMode",
+ description: "Preview mode",
+ category: "Top bar",
defaultHotkeys: ["meta+shift+p", "ctrl+shift+p"],
handler: () => {
setActiveSidebarPanel("auto");
@@ -357,6 +364,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleDesignMode",
+ description: "Toggle design mode",
+ category: "Top bar",
defaultHotkeys: ["meta+shift+d", "ctrl+shift+d"],
handler: () => {
setActiveSidebarPanel("auto");
@@ -365,6 +374,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleContentMode",
+ description: "Toggle content mode",
+ category: "Top bar",
defaultHotkeys: ["meta+shift+c", "ctrl+shift+c"],
handler: () => {
setActiveSidebarPanel("auto");
@@ -373,12 +384,15 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "openBreakpointsMenu",
+ description: "Manage responsive breakpoints",
handler: () => {
$breakpointsMenuView.set("initial");
},
},
{
name: "openPublishDialog",
+ description: "Deploy your project",
+ category: "Top bar",
defaultHotkeys: ["shift+P"],
handler: () => {
$publishDialog.set("publish");
@@ -387,6 +401,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "openExportDialog",
+ description: "Export project code",
+ category: "General",
defaultHotkeys: ["shift+E"],
handler: () => {
$publishDialog.set("export");
@@ -395,6 +411,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleComponentsPanel",
+ description: "Toggle components panel",
+ category: "Panels",
defaultHotkeys: ["a"],
handler: () => {
if ($isDesignMode.get() === false) {
@@ -409,6 +427,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleNavigatorPanel",
+ description: "Toggle navigator panel",
+ category: "Panels",
defaultHotkeys: ["z"],
handler: () => {
toggleActiveSidebarPanel("navigator");
@@ -417,6 +437,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "openStylePanel",
+ description: "Open style panel",
+ category: "Panels",
defaultHotkeys: ["s"],
handler: () => {
if ($isDesignMode.get() === false) {
@@ -431,6 +453,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "focusStyleSources",
+ description: "Focus style sources input",
+ category: "Style panel",
defaultHotkeys: ["meta+enter", "ctrl+enter"],
handler: () => {
if ($isDesignMode.get() === false) {
@@ -448,6 +472,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleStylePanelFocusMode",
+ description: "Toggle style panel focus mode",
+ category: "Style panel",
defaultHotkeys: ["alt+shift+s"],
handler: () => {
setSetting(
@@ -459,6 +485,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "toggleStylePanelAdvancedMode",
+ description: "Toggle style panel advanced mode",
+ category: "Style panel",
defaultHotkeys: ["alt+shift+a"],
handler: () => {
setSetting(
@@ -470,6 +498,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "openSettingsPanel",
+ description: "Open settings panel",
+ category: "Panels",
defaultHotkeys: ["d"],
handler: () => {
$activeInspectorPanel.set("settings");
@@ -485,23 +515,11 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
makeBreakpointCommand("selectBreakpoint7", 7),
makeBreakpointCommand("selectBreakpoint8", 8),
makeBreakpointCommand("selectBreakpoint9", 9),
- /*
- // @todo: decide about keyboard shortcut, uncomment when ready
- {
- name: "toggleAiCommandBar",
- defaultHotkeys: ["space"],
- // this disables hotkey for inputs on style panel
- // but still work for input on canvas which call event.preventDefault() in keydown handler
- disableOnInputLikeControls: true,
- handler: () => {
- $isAiCommandBarVisible.set($isAiCommandBarVisible.get() === false);
- },
- },
- */
-
{
name: "deleteInstanceBuilder",
label: "Delete Instance",
+ description: "Delete selected instance",
+ category: "Navigator",
defaultHotkeys: ["backspace", "delete"],
// See "deleteInstanceCanvas" for details on why the command is separated for the canvas and builder.
disableHotkeyOutsideApp: true,
@@ -510,6 +528,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "duplicateInstance",
+ description: "Duplicate selected instance",
+ category: "Navigator",
defaultHotkeys: ["meta+d", "ctrl+d"],
handler: () => {
const project = $project.get();
@@ -568,6 +588,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "editInstanceLabel",
+ description: "Edit instance label",
+ category: "Navigator",
defaultHotkeys: ["meta+e", "ctrl+e"],
handler: () => {
const instancePath = $selectedInstancePath.get();
@@ -581,31 +603,37 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "wrapInElement",
label: "Wrap in an Element",
+ description: "Wrap in new element",
handler: () => wrapIn(elementComponent),
},
{
name: "wrapInLink",
label: "Wrap in a Link",
+ description: "Wrap in link element",
handler: () => wrapIn(elementComponent, "a"),
},
{
name: "unwrap",
+ description: "Remove parent wrapper",
handler: () => unwrap(),
},
{
name: "replaceWithElement",
label: "Replace with an Element",
+ description: "Replace with element",
handler: () => replaceWith(elementComponent),
},
{
name: "replaceWithLink",
label: "Replace with a Link",
+ description: "Replace with link",
handler: () => replaceWith(elementComponent, "a"),
},
{
name: "pasteTailwind",
label: "Paste HTML with Tailwind classes",
+ description: "Convert Tailwind to CSS",
handler: async () => {
const html = await navigator.clipboard.readText();
let fragment = generateFragmentFromHtml(html);
@@ -619,6 +647,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "undo",
+ description: "Undo last action",
+ category: "General",
// safari use meta+z to reopen closed tabs, here added ctrl as alternative
defaultHotkeys: ["meta+z", "ctrl+z"],
disableOnInputLikeControls: true,
@@ -628,6 +658,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
},
{
name: "redo",
+ description: "Redo last action",
+ category: "General",
// safari use meta+z to reopen closed tabs, here added ctrl as alternative
defaultHotkeys: ["meta+shift+z", "ctrl+shift+z"],
disableOnInputLikeControls: true,
@@ -638,6 +670,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "save",
+ description: "Save project",
+ category: "General",
defaultHotkeys: ["meta+s", "ctrl+s"],
handler: async () => {
toast.dismiss("save-success");
@@ -654,7 +688,8 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "openCommandPanel",
- hidden: true,
+ description: "Open command panel",
+ category: "General",
defaultHotkeys: ["meta+k", "ctrl+k"],
handler: () => {
if ($isDesignMode.get()) {
@@ -666,6 +701,7 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "deleteUnusedTokens",
label: "Delete unused tokens",
+ description: "Remove unused tokens",
handler: () => {
openDeleteUnusedTokensDialog();
},
@@ -674,6 +710,7 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "deleteUnusedDataVariables",
label: "Delete unused data variables",
+ description: "Remove unused data variables",
handler: () => {
openDeleteUnusedDataVariablesDialog();
},
@@ -682,9 +719,20 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
{
name: "deleteUnusedCssVariables",
label: "Delete unused CSS variables",
+ description: "Remove unused CSS variables",
handler: () => {
openDeleteUnusedCssVariablesDialog();
},
},
+
+ {
+ name: "openKeyboardShortcuts",
+ description: "View keyboard shortcuts",
+ category: "General",
+ defaultHotkeys: ["shift+?"],
+ handler: () => {
+ openKeyboardShortcutsDialog();
+ },
+ },
],
});
diff --git a/apps/builder/app/shared/commands-emitter.ts b/apps/builder/app/shared/commands-emitter.ts
index 7fda568409..9b20960d28 100644
--- a/apps/builder/app/shared/commands-emitter.ts
+++ b/apps/builder/app/shared/commands-emitter.ts
@@ -2,10 +2,13 @@ import { atom } from "nanostores";
import { $publisher, subscribe } from "~/shared/pubsub";
import { clientSyncStore } from "~/shared/sync";
-type CommandMeta<CommandName extends string> = {
- // @todo category, description
+export type CommandMeta<CommandName extends string> = {
name: CommandName;
label?: string;
+ /** brief description shown in keyboard shortcuts dialog */
+ description?: string;
+ /** category for grouping commands in UI for shortcuts dialog */
+ category?: "General" | "Panels" | "Navigator" | "Top bar" | "Style panel";
/** default because hotkeys can be customized from ui */
defaultHotkeys?: string[];
/** set to false when default browser or radix behavior is desired */
diff --git a/packages/design-system/src/components/kbd.tsx b/packages/design-system/src/components/kbd.tsx
index 662dadb223..45b7dde554 100644
--- a/packages/design-system/src/components/kbd.tsx
+++ b/packages/design-system/src/components/kbd.tsx
@@ -25,6 +25,28 @@ const format = (value: ShortcutDefinition) => {
);
};
+/**
+ * Filter hotkeys array to show only the appropriate one for current OS.
+ * Prioritizes meta (Mac) or ctrl (Windows/Linux) hotkeys.
+ */
+export const filterHotkeyByOs = (hotkeys: readonly string[]): string => {
+ if (hotkeys.length === 1) {
+ return hotkeys[0];
+ }
+
+ const macHotkey = hotkeys.find((key) => key.includes("meta"));
+ const winHotkey = hotkeys.find((key) => key.includes("ctrl"));
+
+ if (isMac && macHotkey) {
+ return macHotkey;
+ }
+ if (!isMac && winHotkey) {
+ return winHotkey;
+ }
+
+ return hotkeys[0];
+};
+
export const Kbd = ({
value,
color = "subtle",