fix: decouple actionFinalize and actionErase (#4984)
* Update actionCanvas.tsx * Update actionFinalize.tsx * lint * remove Escape trigger from actionErase * revert to lastActiveTool only if coming from eraser tool * unrelated: fix restoring `appState.activeTool` * one more restoring fix * fix tests Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
f2d2f97546
commit
734bb4d2ed
@ -323,12 +323,7 @@ export const actionErase = register({
|
|||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event, appState) => {
|
keyTest: (event) => event.key === KEYS.E,
|
||||||
return (
|
|
||||||
event.key === KEYS.E ||
|
|
||||||
(event.key === KEYS.ESCAPE && isEraserActive(appState))
|
|
||||||
);
|
|
||||||
},
|
|
||||||
PanelComponent: ({ elements, appState, updateData, data }) => (
|
PanelComponent: ({ elements, appState, updateData, data }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -14,7 +14,6 @@ import {
|
|||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
} from "../element/binding";
|
} from "../element/binding";
|
||||||
import { isBindingElement } from "../element/typeChecks";
|
import { isBindingElement } from "../element/typeChecks";
|
||||||
import { isEraserActive } from "../appState";
|
|
||||||
|
|
||||||
export const actionFinalize = register({
|
export const actionFinalize = register({
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
@ -146,7 +145,14 @@ export const actionFinalize = register({
|
|||||||
appState.activeTool.type === "freedraw") &&
|
appState.activeTool.type === "freedraw") &&
|
||||||
multiPointElement
|
multiPointElement
|
||||||
? appState.activeTool
|
? appState.activeTool
|
||||||
: { ...appState.activeTool, type: "selection" },
|
: {
|
||||||
|
...appState.activeTool,
|
||||||
|
type:
|
||||||
|
appState.activeTool.type === "eraser" &&
|
||||||
|
appState.activeTool.lastActiveToolBeforeEraser
|
||||||
|
? appState.activeTool.lastActiveToolBeforeEraser
|
||||||
|
: "selection",
|
||||||
|
},
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
editingElement: null,
|
editingElement: null,
|
||||||
@ -167,12 +173,11 @@ export const actionFinalize = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event, appState) =>
|
keyTest: (event, appState) =>
|
||||||
!isEraserActive(appState) &&
|
(event.key === KEYS.ESCAPE &&
|
||||||
((event.key === KEYS.ESCAPE &&
|
|
||||||
(appState.editingLinearElement !== null ||
|
(appState.editingLinearElement !== null ||
|
||||||
(!appState.draggingElement && appState.multiElement === null))) ||
|
(!appState.draggingElement && appState.multiElement === null))) ||
|
||||||
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
||||||
appState.multiElement !== null)),
|
appState.multiElement !== null),
|
||||||
PanelComponent: ({ appState, updateData, data }) => (
|
PanelComponent: ({ appState, updateData, data }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -252,9 +252,13 @@ export const restoreAppState = (
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...nextAppState,
|
...nextAppState,
|
||||||
activeTool: AllowedExcalidrawActiveTools[nextAppState.activeTool.type]
|
activeTool: {
|
||||||
? nextAppState.activeTool
|
lastActiveToolBeforeEraser: null,
|
||||||
: { ...nextAppState.activeTool, type: "selection" },
|
locked: nextAppState.activeTool.locked ?? false,
|
||||||
|
type: AllowedExcalidrawActiveTools[nextAppState.activeTool.type]
|
||||||
|
? nextAppState.activeTool.type ?? "selection"
|
||||||
|
: "selection",
|
||||||
|
},
|
||||||
// Migrates from previous version where appState.zoom was a number
|
// Migrates from previous version where appState.zoom was a number
|
||||||
zoom:
|
zoom:
|
||||||
typeof appState.zoom === "number"
|
typeof appState.zoom === "number"
|
||||||
|
@ -310,7 +310,9 @@ describe("restoreAppState", () => {
|
|||||||
stubImportedAppState,
|
stubImportedAppState,
|
||||||
stubLocalAppState,
|
stubLocalAppState,
|
||||||
);
|
);
|
||||||
expect(restoredAppState.activeTool).toBe(stubImportedAppState.activeTool);
|
expect(restoredAppState.activeTool).toEqual(
|
||||||
|
stubImportedAppState.activeTool,
|
||||||
|
);
|
||||||
expect(restoredAppState.cursorButton).toBe(
|
expect(restoredAppState.cursorButton).toBe(
|
||||||
stubImportedAppState.cursorButton,
|
stubImportedAppState.cursorButton,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user