diff --git a/src/actions/actionToggleGridMode.tsx b/src/actions/actionToggleGridMode.tsx index 22e8e558..e99e3a01 100644 --- a/src/actions/actionToggleGridMode.tsx +++ b/src/actions/actionToggleGridMode.tsx @@ -1,21 +1,20 @@ import { CODES, KEYS } from "../keys"; import { register } from "./register"; import { GRID_SIZE } from "../constants"; +import { AppState } from "../types"; export const actionToggleGridMode = register({ name: "gridMode", perform(elements, appState) { - this.checked = !this.checked; return { appState: { ...appState, - gridSize: this.checked ? GRID_SIZE : null, + gridSize: this.checked!(appState) ? null : GRID_SIZE, }, commitToHistory: false, }; }, - checked: false, + checked: (appState: AppState) => appState.gridSize !== null, contextItemLabel: "labels.gridMode", - // Wrong event code keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE, }); diff --git a/src/actions/actionToggleStats.tsx b/src/actions/actionToggleStats.tsx index 1d75caf8..3c03b80c 100644 --- a/src/actions/actionToggleStats.tsx +++ b/src/actions/actionToggleStats.tsx @@ -3,15 +3,14 @@ import { register } from "./register"; export const actionToggleStats = register({ name: "stats", perform(elements, appState) { - this.checked = !this.checked; return { appState: { ...appState, - showStats: !appState.showStats, + showStats: !this.checked!(appState), }, commitToHistory: false, }; }, - checked: false, + checked: (appState) => appState.showStats, contextItemLabel: "stats.title", }); diff --git a/src/actions/actionToggleZenMode.tsx b/src/actions/actionToggleZenMode.tsx index 32ddd6fe..38da9cde 100644 --- a/src/actions/actionToggleZenMode.tsx +++ b/src/actions/actionToggleZenMode.tsx @@ -4,17 +4,16 @@ import { register } from "./register"; export const actionToggleZenMode = register({ name: "zenMode", perform(elements, appState) { - this.checked = !this.checked; return { appState: { ...appState, - zenModeEnabled: this.checked, + zenModeEnabled: !this.checked!(appState), }, commitToHistory: false, }; }, - checked: false, + checked: (appState) => appState.zenModeEnabled, contextItemLabel: "buttons.zenMode", - // Wrong event code - keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE, + keyTest: (event) => + !event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.Z, }); diff --git a/src/actions/types.ts b/src/actions/types.ts index 6d373faa..66f8dece 100644 --- a/src/actions/types.ts +++ b/src/actions/types.ts @@ -106,7 +106,7 @@ export interface Action { elements: readonly ExcalidrawElement[], appState: AppState, ) => boolean; - checked?: boolean; + checked?: (appState: Readonly) => boolean; } export interface ActionsManagerInterface { diff --git a/src/components/App.tsx b/src/components/App.tsx index c8e321be..795d2def 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1254,7 +1254,6 @@ class App extends React.Component { if (!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.Z) { this.toggleZenMode(); } - if (event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE) { this.toggleGridMode(); } @@ -3663,6 +3662,7 @@ class App extends React.Component { top: clientY, left: clientX, actionManager: this.actionManager, + appState: this.state, }); return; } @@ -3709,6 +3709,7 @@ class App extends React.Component { top: clientY, left: clientX, actionManager: this.actionManager, + appState: this.state, }); }; diff --git a/src/components/ContextMenu.tsx b/src/components/ContextMenu.tsx index 567d9dd4..17556665 100644 --- a/src/components/ContextMenu.tsx +++ b/src/components/ContextMenu.tsx @@ -11,6 +11,7 @@ import { } from "../actions/shortcuts"; import { Action } from "../actions/types"; import { ActionManager } from "../actions/manager"; +import { AppState } from "../types"; type ContextMenuOption = "separator" | Action; @@ -20,6 +21,7 @@ type ContextMenuProps = { top: number; left: number; actionManager: ActionManager; + appState: Readonly; }; const ContextMenu = ({ @@ -28,11 +30,11 @@ const ContextMenu = ({ top, left, actionManager, + appState, }: ContextMenuProps) => { const isDarkTheme = !!document .querySelector(".excalidraw") ?.classList.contains("Appearance_dark"); - return (