fix: replaced KeyboardEvent.code with KeyboardEvent.key for all letters (#5523)

* fix: Replaced KeyboardEvent.code with KeyboardEvent.key for all letters

* fix: reverted all keybindings that included alt to use code instead of keys

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
Jakob Guddas 2022-10-20 21:01:26 +02:00 committed by GitHub
parent 55110bf1b8
commit 79bd3b8cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 21 deletions

View File

@ -36,7 +36,7 @@ export const actionCut = register({
return actionDeleteSelected.perform(elements, appState); return actionDeleteSelected.perform(elements, appState);
}, },
contextItemLabel: "labels.cut", contextItemLabel: "labels.cut",
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.X, keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.X,
}); });
export const actionCopyAsSvg = register({ export const actionCopyAsSvg = register({

View File

@ -1,4 +1,4 @@
import { CODES, KEYS } from "../keys"; import { KEYS } from "../keys";
import { t } from "../i18n"; import { t } from "../i18n";
import { arrayToMap, getShortcutKey } from "../utils"; import { arrayToMap, getShortcutKey } from "../utils";
import { register } from "./register"; import { register } from "./register";
@ -132,7 +132,7 @@ export const actionGroup = register({
contextItemPredicate: (elements, appState) => contextItemPredicate: (elements, appState) =>
enableActionGroup(elements, appState), enableActionGroup(elements, appState),
keyTest: (event) => keyTest: (event) =>
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G, !event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.key === KEYS.G,
PanelComponent: ({ elements, appState, updateData }) => ( PanelComponent: ({ elements, appState, updateData }) => (
<ToolButton <ToolButton
hidden={!enableActionGroup(elements, appState)} hidden={!enableActionGroup(elements, appState)}
@ -189,7 +189,7 @@ export const actionUngroup = register({
}; };
}, },
keyTest: (event) => keyTest: (event) =>
event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G, event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.key === KEYS.G,
contextItemLabel: "labels.ungroup", contextItemLabel: "labels.ungroup",
contextItemPredicate: (elements, appState) => contextItemPredicate: (elements, appState) =>
getSelectedGroupIds(appState).length > 0, getSelectedGroupIds(appState).length > 0,

View File

@ -4,7 +4,7 @@ import { t } from "../i18n";
import { showSelectedShapeActions, getNonDeletedElements } from "../element"; import { showSelectedShapeActions, getNonDeletedElements } from "../element";
import { register } from "./register"; import { register } from "./register";
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils"; import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
import { CODES, KEYS } from "../keys"; import { KEYS } from "../keys";
import { HelpIcon } from "../components/HelpIcon"; import { HelpIcon } from "../components/HelpIcon";
export const actionToggleCanvasMenu = register({ export const actionToggleCanvasMenu = register({
@ -67,7 +67,7 @@ export const actionFullScreen = register({
commitToHistory: false, commitToHistory: false,
}; };
}, },
keyTest: (event) => event.code === CODES.F && !event[KEYS.CTRL_OR_CMD], keyTest: (event) => event.key === KEYS.F && !event[KEYS.CTRL_OR_CMD],
}); });
export const actionShortcuts = register({ export const actionShortcuts = register({

View File

@ -18,11 +18,8 @@ export const CODES = {
SLASH: "Slash", SLASH: "Slash",
C: "KeyC", C: "KeyC",
D: "KeyD", D: "KeyD",
G: "KeyG",
F: "KeyF",
H: "KeyH", H: "KeyH",
V: "KeyV", V: "KeyV",
X: "KeyX",
Z: "KeyZ", Z: "KeyZ",
R: "KeyR", R: "KeyR",
} as const; } as const;
@ -47,9 +44,12 @@ export const KEYS = {
COMMA: ",", COMMA: ",",
A: "a", A: "a",
C: "c",
D: "d", D: "d",
E: "e", E: "e",
F: "f",
G: "g", G: "g",
H: "h",
I: "i", I: "i",
L: "l", L: "l",
O: "o", O: "o",

View File

@ -14,7 +14,7 @@ import ExcalidrawApp from "../excalidraw-app";
import * as Renderer from "../renderer/renderScene"; import * as Renderer from "../renderer/renderScene";
import { reseed } from "../random"; import { reseed } from "../random";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";
import { CODES } from "../keys"; import { KEYS } from "../keys";
import { ShortcutName } from "../actions/shortcuts"; import { ShortcutName } from "../actions/shortcuts";
import { copiedStyles } from "../actions/actionStyles"; import { copiedStyles } from "../actions/actionStyles";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
@ -240,7 +240,7 @@ describe("contextMenu element", () => {
}); });
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
fireEvent.contextMenu(GlobalTestState.canvas, { fireEvent.contextMenu(GlobalTestState.canvas, {
@ -537,7 +537,7 @@ describe("contextMenu element", () => {
}); });
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
fireEvent.contextMenu(GlobalTestState.canvas, { fireEvent.contextMenu(GlobalTestState.canvas, {

View File

@ -3,7 +3,7 @@ import {
ExcalidrawLinearElement, ExcalidrawLinearElement,
ExcalidrawTextElement, ExcalidrawTextElement,
} from "../../element/types"; } from "../../element/types";
import { CODES } from "../../keys"; import { KEYS } from "../../keys";
import { ToolName } from "../queries/toolQueries"; import { ToolName } from "../queries/toolQueries";
import { fireEvent, GlobalTestState } from "../test-utils"; import { fireEvent, GlobalTestState } from "../test-utils";
import { mutateElement } from "../../element/mutateElement"; import { mutateElement } from "../../element/mutateElement";
@ -314,7 +314,7 @@ export class UI {
static group(elements: ExcalidrawElement[]) { static group(elements: ExcalidrawElement[]) {
mouse.select(elements); mouse.select(elements);
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
} }

View File

@ -485,7 +485,7 @@ describe("regression tests", () => {
} }
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
for (const element of h.elements) { for (const element of h.elements) {
@ -524,7 +524,7 @@ describe("regression tests", () => {
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A); Keyboard.keyPress(KEYS.A);
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
expect(API.getSelectedElements().length).toBe(3); expect(API.getSelectedElements().length).toBe(3);
@ -561,7 +561,7 @@ describe("regression tests", () => {
mouse.click(); mouse.click();
}); });
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
expect(h.elements.map((element) => element.id)).toEqual([ expect(h.elements.map((element) => element.id)).toEqual([
@ -578,7 +578,7 @@ describe("regression tests", () => {
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A); Keyboard.keyPress(KEYS.A);
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
mouse.doubleClickOn(rectC); mouse.doubleClickOn(rectC);
@ -586,7 +586,7 @@ describe("regression tests", () => {
mouse.clickOn(rectA); mouse.clickOn(rectA);
}); });
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
expect(rectC.groupIds.length).toBe(2); expect(rectC.groupIds.length).toBe(2);
@ -996,7 +996,7 @@ describe("regression tests", () => {
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A); Keyboard.keyPress(KEYS.A);
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
const selectedGroupIds_prev = h.state.selectedGroupIds; const selectedGroupIds_prev = h.state.selectedGroupIds;
@ -1110,7 +1110,7 @@ it(
// Create group with first and third rectangle // Create group with first and third rectangle
Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.codePress(CODES.G); Keyboard.keyPress(KEYS.G);
}); });
expect(API.getSelectedElements().length).toBe(2); expect(API.getSelectedElements().length).toBe(2);