mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge 627f1dd036
into 2a0d15799c
This commit is contained in:
commit
83163d8da7
2 changed files with 19 additions and 2 deletions
|
@ -486,7 +486,7 @@ import {
|
||||||
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
||||||
import { Toast } from "./Toast";
|
import { Toast } from "./Toast";
|
||||||
|
|
||||||
import { findShapeByKey } from "./shapes";
|
import { findShapeByCode, findShapeByKey } from "./shapes";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
RenderInteractiveSceneCallback,
|
RenderInteractiveSceneCallback,
|
||||||
|
@ -4511,7 +4511,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
!this.state.selectionElement &&
|
!this.state.selectionElement &&
|
||||||
!this.state.selectedElementsAreBeingDragged
|
!this.state.selectedElementsAreBeingDragged
|
||||||
) {
|
) {
|
||||||
const shape = findShapeByKey(event.key);
|
const shape = findShapeByKey(event.key) || findShapeByCode(event.code);
|
||||||
if (shape) {
|
if (shape) {
|
||||||
if (this.state.activeTool.type !== shape) {
|
if (this.state.activeTool.type !== shape) {
|
||||||
trackEvent(
|
trackEvent(
|
||||||
|
|
|
@ -18,6 +18,7 @@ export const SHAPES = [
|
||||||
icon: SelectionIcon,
|
icon: SelectionIcon,
|
||||||
value: "selection",
|
value: "selection",
|
||||||
key: KEYS.V,
|
key: KEYS.V,
|
||||||
|
codes: ["KeyV", "Digit1"],
|
||||||
numericKey: KEYS["1"],
|
numericKey: KEYS["1"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -25,6 +26,7 @@ export const SHAPES = [
|
||||||
icon: RectangleIcon,
|
icon: RectangleIcon,
|
||||||
value: "rectangle",
|
value: "rectangle",
|
||||||
key: KEYS.R,
|
key: KEYS.R,
|
||||||
|
codes: ["KeyR", "Digit2"],
|
||||||
numericKey: KEYS["2"],
|
numericKey: KEYS["2"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -32,6 +34,7 @@ export const SHAPES = [
|
||||||
icon: DiamondIcon,
|
icon: DiamondIcon,
|
||||||
value: "diamond",
|
value: "diamond",
|
||||||
key: KEYS.D,
|
key: KEYS.D,
|
||||||
|
codes: ["KeyD", "Digit3"],
|
||||||
numericKey: KEYS["3"],
|
numericKey: KEYS["3"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -39,6 +42,7 @@ export const SHAPES = [
|
||||||
icon: EllipseIcon,
|
icon: EllipseIcon,
|
||||||
value: "ellipse",
|
value: "ellipse",
|
||||||
key: KEYS.O,
|
key: KEYS.O,
|
||||||
|
codes: ["KeyO", "Digit4"],
|
||||||
numericKey: KEYS["4"],
|
numericKey: KEYS["4"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -46,6 +50,7 @@ export const SHAPES = [
|
||||||
icon: ArrowIcon,
|
icon: ArrowIcon,
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
key: KEYS.A,
|
key: KEYS.A,
|
||||||
|
codes: ["KeyA", "Digit5"],
|
||||||
numericKey: KEYS["5"],
|
numericKey: KEYS["5"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -53,6 +58,7 @@ export const SHAPES = [
|
||||||
icon: LineIcon,
|
icon: LineIcon,
|
||||||
value: "line",
|
value: "line",
|
||||||
key: KEYS.L,
|
key: KEYS.L,
|
||||||
|
codes: ["KeyL", "Digit6"],
|
||||||
numericKey: KEYS["6"],
|
numericKey: KEYS["6"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
},
|
},
|
||||||
|
@ -60,6 +66,7 @@ export const SHAPES = [
|
||||||
icon: FreedrawIcon,
|
icon: FreedrawIcon,
|
||||||
value: "freedraw",
|
value: "freedraw",
|
||||||
key: [KEYS.P, KEYS.X],
|
key: [KEYS.P, KEYS.X],
|
||||||
|
codes: ["KeyP", "KeyX", "Digit7"],
|
||||||
numericKey: KEYS["7"],
|
numericKey: KEYS["7"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
},
|
},
|
||||||
|
@ -67,6 +74,7 @@ export const SHAPES = [
|
||||||
icon: TextIcon,
|
icon: TextIcon,
|
||||||
value: "text",
|
value: "text",
|
||||||
key: KEYS.T,
|
key: KEYS.T,
|
||||||
|
codes: ["KeyT", "Digit8"],
|
||||||
numericKey: KEYS["8"],
|
numericKey: KEYS["8"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
},
|
},
|
||||||
|
@ -74,6 +82,7 @@ export const SHAPES = [
|
||||||
icon: ImageIcon,
|
icon: ImageIcon,
|
||||||
value: "image",
|
value: "image",
|
||||||
key: null,
|
key: null,
|
||||||
|
codes: ["Digit9"],
|
||||||
numericKey: KEYS["9"],
|
numericKey: KEYS["9"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
},
|
},
|
||||||
|
@ -81,6 +90,7 @@ export const SHAPES = [
|
||||||
icon: EraserIcon,
|
icon: EraserIcon,
|
||||||
value: "eraser",
|
value: "eraser",
|
||||||
key: KEYS.E,
|
key: KEYS.E,
|
||||||
|
codes: ["KeyE", "Digit0"],
|
||||||
numericKey: KEYS["0"],
|
numericKey: KEYS["0"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
},
|
},
|
||||||
|
@ -98,3 +108,10 @@ export const findShapeByKey = (key: string) => {
|
||||||
});
|
});
|
||||||
return shape?.value || null;
|
return shape?.value || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findShapeByCode = (code: string) => {
|
||||||
|
const shape = SHAPES.find((shape) =>
|
||||||
|
(shape.codes as readonly string[]).includes(code),
|
||||||
|
);
|
||||||
|
return shape?.value || null;
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue