mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-21 16:29:58 +02:00
Compare commits
1 Commits
zsviczian-
...
feat-actio
Author | SHA1 | Date | |
---|---|---|---|
![]() |
60bab6a428 |
@@ -2,11 +2,12 @@ import { isDarwin } from "../constants";
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { SubtypeOf } from "../utility-types";
|
import { SubtypeOf } from "../utility-types";
|
||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { ActionName } from "./types";
|
import { ActionName, CustomActionName } from "./types";
|
||||||
|
|
||||||
export type ShortcutName =
|
export type ShortcutName =
|
||||||
| SubtypeOf<
|
| SubtypeOf<
|
||||||
ActionName,
|
ActionName,
|
||||||
|
| CustomActionName
|
||||||
| "toggleTheme"
|
| "toggleTheme"
|
||||||
| "loadScene"
|
| "loadScene"
|
||||||
| "clearCanvas"
|
| "clearCanvas"
|
||||||
@@ -40,6 +41,15 @@ export type ShortcutName =
|
|||||||
| "saveScene"
|
| "saveScene"
|
||||||
| "imageExport";
|
| "imageExport";
|
||||||
|
|
||||||
|
export const registerCustomShortcuts = (
|
||||||
|
shortcuts: Record<CustomActionName, string[]>,
|
||||||
|
) => {
|
||||||
|
for (const key in shortcuts) {
|
||||||
|
const shortcut = key as CustomActionName;
|
||||||
|
shortcutMap[shortcut] = shortcuts[shortcut];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const shortcutMap: Record<ShortcutName, string[]> = {
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
||||||
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
||||||
saveScene: [getShortcutKey("CtrlOrCmd+S")],
|
saveScene: [getShortcutKey("CtrlOrCmd+S")],
|
||||||
|
@@ -35,7 +35,11 @@ type ActionFn = (
|
|||||||
export type UpdaterFn = (res: ActionResult) => void;
|
export type UpdaterFn = (res: ActionResult) => void;
|
||||||
export type ActionFilterFn = (action: Action) => void;
|
export type ActionFilterFn = (action: Action) => void;
|
||||||
|
|
||||||
|
export const makeCustomActionName = (name: string) =>
|
||||||
|
`custom.${name}` as CustomActionName;
|
||||||
|
export type CustomActionName = `custom.${string}`;
|
||||||
export type ActionName =
|
export type ActionName =
|
||||||
|
| CustomActionName
|
||||||
| "copy"
|
| "copy"
|
||||||
| "cut"
|
| "cut"
|
||||||
| "paste"
|
| "paste"
|
||||||
|
@@ -461,7 +461,7 @@ export const wrapText = (text: string, font: FontString, maxWidth: number) => {
|
|||||||
|
|
||||||
const push = (str: string) => {
|
const push = (str: string) => {
|
||||||
if (str.trim()) {
|
if (str.trim()) {
|
||||||
lines.push(str.trim());
|
lines.push(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1173,7 +1173,7 @@ describe("textWysiwyg", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect((h.elements[1] as ExcalidrawTextElementWithContainer).text).toBe(
|
expect((h.elements[1] as ExcalidrawTextElementWithContainer).text).toBe(
|
||||||
"Online\nwhitebo\nard\ncollabo\nration\nmade\neasy",
|
"Online \nwhitebo\nard \ncollabo\nration \nmade \neasy",
|
||||||
);
|
);
|
||||||
fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
|
fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
|
||||||
button: 2,
|
button: 2,
|
||||||
|
Reference in New Issue
Block a user