Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: add ctrl-y to redo (#2831)

David Luzar9dc930b44744
diff --git a/src/actions/actionHistory.tsx b/src/actions/actionHistory.tsx
index 9e3f62321b..c0971c2ef0 100644
--- a/src/actions/actionHistory.tsx
+++ b/src/actions/actionHistory.tsx
@@ -6,7 +6,7 @@ import { t } from "../i18n";
import { SceneHistory, HistoryEntry } from "../history";
import { ExcalidrawElement } from "../element/types";
import { AppState } from "../types";
-import { KEYS } from "../keys";
+import { isWindows, KEYS } from "../keys";
import { getElementMap } from "../element";
import { newElementWith } from "../element/mutateElement";
import { fixBindingsAfterDeletion } from "../element/binding";
@@ -59,16 +59,16 @@ const writeData = (
return { commitToHistory };
};
-const testUndo = (shift: boolean) => (event: KeyboardEvent) =>
- event[KEYS.CTRL_OR_CMD] && /z/i.test(event.key) && event.shiftKey === shift;
-
type ActionCreator = (history: SceneHistory) => Action;
export const createUndoAction: ActionCreator = (history) => ({
name: "undo",
perform: (elements, appState) =>
writeData(elements, appState, () => history.undoOnce()),
- keyTest: testUndo(false),
+ keyTest: (event) =>
+ event[KEYS.CTRL_OR_CMD] &&
+ event.key.toLowerCase() === KEYS.Z &&
+ !event.shiftKey,
PanelComponent: ({ updateData }) => (
<ToolButton
type="button"
@@ -84,7 +84,11 @@ export const createRedoAction: ActionCreator = (history) => ({
name: "redo",
perform: (elements, appState) =>
writeData(elements, appState, () => history.redoOnce()),
- keyTest: testUndo(true),
+ keyTest: (event) =>
+ (event[KEYS.CTRL_OR_CMD] &&
+ event.shiftKey &&
+ event.key.toLowerCase() === KEYS.Z) ||
+ (isWindows && event.ctrlKey && !event.shiftKey && event.key === KEYS.Y),
PanelComponent: ({ updateData }) => (
<ToolButton
type="button"
diff --git a/src/components/HelpDialog.tsx b/src/components/HelpDialog.tsx
index fa72a2da55..2a80647636 100644
--- a/src/components/HelpDialog.tsx
+++ b/src/components/HelpDialog.tsx
@@ -1,6 +1,6 @@
import React from "react";
import { t } from "../i18n";
-import { isDarwin } from "../keys";
+import { isDarwin, isWindows } from "../keys";
import { Dialog } from "./Dialog";
import { getShortcutKey } from "../utils";
import "./HelpDialog.scss";
@@ -328,7 +328,14 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
/>
<Shortcut
label={t("buttons.redo")}
- shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Z")]}
+ shortcuts={
+ isWindows
+ ? [
+ getShortcutKey("CtrlOrCmd+Y"),
+ getShortcutKey("CtrlOrCmd+Shift+Z"),
+ ]
+ : [getShortcutKey("CtrlOrCmd+Shift+Z")]
+ }
/>
<Shortcut
label={t("labels.group")}
diff --git a/src/keys.ts b/src/keys.ts
index 9e0cd2ac9e..54ec2e0ea1 100644
--- a/src/keys.ts
+++ b/src/keys.ts
@@ -1,4 +1,5 @@
export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
+export const isWindows = /^Win/.test(window.navigator.platform);
export const CODES = {
EQUAL: "Equal",
@@ -48,6 +49,7 @@ export const KEYS = {
T: "t",
V: "v",
X: "x",
+ Y: "y",
Z: "z",
} as const;
diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md
index 7b8de509ce..7ab2dd7cd9 100644
--- a/src/packages/excalidraw/CHANGELOG.md
+++ b/src/packages/excalidraw/CHANGELOG.md
@@ -12,6 +12,14 @@ The change should be grouped under one of the below section and must contain PR
Please add the latest change on the top under the correct section.
-->
+## [Unreleased]
+
+## Excalidraw Library
+
+### Features
+
+- Support `Ctrl-Y` shortcut to redo on Windows [#2831](https://github.com/excalidraw/excalidraw/pull/2831).
+
## 0.2.1
## Excalidraw API