Skip to content

Commit

Permalink
feat: add "toggle grid" to command palette (excalidraw#7887)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Apr 13, 2024
1 parent 9e9bb80 commit 82991a8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/excalidraw/actions/actionToggleGridMode.tsx
Expand Up @@ -2,10 +2,13 @@ import { CODES, KEYS } from "../keys";
import { register } from "./register";
import { GRID_SIZE } from "../constants";
import { AppState } from "../types";
import { gridIcon } from "../components/icons";

export const actionToggleGridMode = register({
name: "gridMode",
label: "labels.showGrid",
icon: gridIcon,
keywords: ["snap"],
label: "labels.toggleGrid",
viewMode: true,
trackEvent: {
category: "canvas",
Expand Down
Expand Up @@ -309,6 +309,7 @@ function CommandPaletteInner({
actionManager.actions.zoomToFit,
actionManager.actions.zenMode,
actionManager.actions.viewMode,
actionManager.actions.gridMode,
actionManager.actions.objectsSnapMode,
actionManager.actions.toggleShortcuts,
actionManager.actions.selectAll,
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/components/HelpDialog.tsx
Expand Up @@ -273,7 +273,7 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
shortcuts={[getShortcutKey("Alt+S")]}
/>
<Shortcut
label={t("labels.showGrid")}
label={t("labels.toggleGrid")}
shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
/>
<Shortcut
Expand Down
13 changes: 13 additions & 0 deletions packages/excalidraw/components/icons.tsx
Expand Up @@ -2115,3 +2115,16 @@ export const youtubeIcon = createIcon(
</g>,
tablerIconProps,
);

export const gridIcon = createIcon(
<g strokeWidth={1.5}>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M3 6h18" />
<path d="M3 12h18" />
<path d="M3 18h18" />
<path d="M6 3v18" />
<path d="M12 3v18" />
<path d="M18 3v18" />
</g>,
tablerIconProps,
);
2 changes: 1 addition & 1 deletion packages/excalidraw/locales/en.json
Expand Up @@ -87,7 +87,7 @@
"group": "Group selection",
"ungroup": "Ungroup selection",
"collaborators": "Collaborators",
"showGrid": "Show grid",
"toggleGrid": "Toggle grid",
"addToLibrary": "Add to library",
"removeFromLibrary": "Remove from library",
"libraryLoadingMessage": "Loading library…",
Expand Down
Expand Up @@ -7781,8 +7781,51 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app
"separator",
{
"checked": [Function],
"icon": <svg
aria-hidden="true"
className=""
fill="none"
focusable="false"
role="img"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
viewBox="0 0 24 24"
>
<g
strokeWidth={1.5}
>
<path
d="M0 0h24v24H0z"
fill="none"
stroke="none"
/>
<path
d="M3 6h18"
/>
<path
d="M3 12h18"
/>
<path
d="M3 18h18"
/>
<path
d="M6 3v18"
/>
<path
d="M12 3v18"
/>
<path
d="M18 3v18"
/>
</g>
</svg>,
"keyTest": [Function],
"label": "labels.showGrid",
"keywords": [
"snap",
],
"label": "labels.toggleGrid",
"name": "gridMode",
"perform": [Function],
"predicate": [Function],
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/tests/excalidraw.test.tsx
Expand Up @@ -101,7 +101,7 @@ describe("<Excalidraw/>", () => {
clientY: 1,
});
const contextMenu = document.querySelector(".context-menu");
fireEvent.click(queryByText(contextMenu as HTMLElement, "Show grid")!);
fireEvent.click(queryByText(contextMenu as HTMLElement, "Toggle grid")!);
expect(h.state.gridSize).toBe(GRID_SIZE);
});

Expand Down

0 comments on commit 82991a8

Please sign in to comment.