Browse Source

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

David Luzar 4 năm trước cách đây
mục cha
commit
9dc930b447

+ 10 - 6
src/actions/actionHistory.tsx

@@ -6,7 +6,7 @@ import { t } from "../i18n";
 import { SceneHistory, HistoryEntry } from "../history";
 import { SceneHistory, HistoryEntry } from "../history";
 import { ExcalidrawElement } from "../element/types";
 import { ExcalidrawElement } from "../element/types";
 import { AppState } from "../types";
 import { AppState } from "../types";
-import { KEYS } from "../keys";
+import { isWindows, KEYS } from "../keys";
 import { getElementMap } from "../element";
 import { getElementMap } from "../element";
 import { newElementWith } from "../element/mutateElement";
 import { newElementWith } from "../element/mutateElement";
 import { fixBindingsAfterDeletion } from "../element/binding";
 import { fixBindingsAfterDeletion } from "../element/binding";
@@ -59,16 +59,16 @@ const writeData = (
   return { commitToHistory };
   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;
 type ActionCreator = (history: SceneHistory) => Action;
 
 
 export const createUndoAction: ActionCreator = (history) => ({
 export const createUndoAction: ActionCreator = (history) => ({
   name: "undo",
   name: "undo",
   perform: (elements, appState) =>
   perform: (elements, appState) =>
     writeData(elements, appState, () => history.undoOnce()),
     writeData(elements, appState, () => history.undoOnce()),
-  keyTest: testUndo(false),
+  keyTest: (event) =>
+    event[KEYS.CTRL_OR_CMD] &&
+    event.key.toLowerCase() === KEYS.Z &&
+    !event.shiftKey,
   PanelComponent: ({ updateData }) => (
   PanelComponent: ({ updateData }) => (
     <ToolButton
     <ToolButton
       type="button"
       type="button"
@@ -84,7 +84,11 @@ export const createRedoAction: ActionCreator = (history) => ({
   name: "redo",
   name: "redo",
   perform: (elements, appState) =>
   perform: (elements, appState) =>
     writeData(elements, appState, () => history.redoOnce()),
     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 }) => (
   PanelComponent: ({ updateData }) => (
     <ToolButton
     <ToolButton
       type="button"
       type="button"

+ 9 - 2
src/components/HelpDialog.tsx

@@ -1,6 +1,6 @@
 import React from "react";
 import React from "react";
 import { t } from "../i18n";
 import { t } from "../i18n";
-import { isDarwin } from "../keys";
+import { isDarwin, isWindows } from "../keys";
 import { Dialog } from "./Dialog";
 import { Dialog } from "./Dialog";
 import { getShortcutKey } from "../utils";
 import { getShortcutKey } from "../utils";
 import "./HelpDialog.scss";
 import "./HelpDialog.scss";
@@ -328,7 +328,14 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
                 />
                 />
                 <Shortcut
                 <Shortcut
                   label={t("buttons.redo")}
                   label={t("buttons.redo")}
-                  shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Z")]}
+                  shortcuts={
+                    isWindows
+                      ? [
+                          getShortcutKey("CtrlOrCmd+Y"),
+                          getShortcutKey("CtrlOrCmd+Shift+Z"),
+                        ]
+                      : [getShortcutKey("CtrlOrCmd+Shift+Z")]
+                  }
                 />
                 />
                 <Shortcut
                 <Shortcut
                   label={t("labels.group")}
                   label={t("labels.group")}

+ 2 - 0
src/keys.ts

@@ -1,4 +1,5 @@
 export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
 export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
+export const isWindows = /^Win/.test(window.navigator.platform);
 
 
 export const CODES = {
 export const CODES = {
   EQUAL: "Equal",
   EQUAL: "Equal",
@@ -48,6 +49,7 @@ export const KEYS = {
   T: "t",
   T: "t",
   V: "v",
   V: "v",
   X: "x",
   X: "x",
+  Y: "y",
   Z: "z",
   Z: "z",
 } as const;
 } as const;
 
 

+ 8 - 0
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.
 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
 ## 0.2.1
 
 
 ## Excalidraw API
 ## Excalidraw API