Compare commits

..

4 Commits

Author SHA1 Message Date
Ryan Di
ae88ea555c simplify code 2023-11-22 17:35:44 +08:00
Ryan Di
14eecf651f merge with master 2023-11-22 17:23:13 +08:00
Ryan Di
c951a001f7 keep resizing logic in sync with master 2023-11-22 17:21:13 +08:00
Ryan Di
25ab75cb9b wip: resizing multiple frames resizes frame children 2023-11-17 19:50:15 +08:00
3 changed files with 22 additions and 49 deletions

View File

@@ -2,12 +2,11 @@ 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, CustomActionName } from "./types"; import { ActionName } from "./types";
export type ShortcutName = export type ShortcutName =
| SubtypeOf< | SubtypeOf<
ActionName, ActionName,
| CustomActionName
| "toggleTheme" | "toggleTheme"
| "loadScene" | "loadScene"
| "clearCanvas" | "clearCanvas"
@@ -41,15 +40,6 @@ 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")],

View File

@@ -35,11 +35,7 @@ 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"

View File

@@ -8238,27 +8238,8 @@ class App extends React.Component<AppProps, AppState> {
event[KEYS.CTRL_OR_CMD] ? null : this.state.gridSize, event[KEYS.CTRL_OR_CMD] ? null : this.state.gridSize,
); );
const frameElementsOffsetsMap = new Map< const resizingSingleFrameOnly =
string, selectedElements.length === 1 && selectedFrames.length === 1;
{
x: number;
y: number;
}
>();
selectedFrames.forEach((frame) => {
const elementsInFrame = getFrameChildren(
this.scene.getNonDeletedElements(),
frame.id,
);
elementsInFrame.forEach((element) => {
frameElementsOffsetsMap.set(frame.id + element.id, {
x: element.x - frame.x,
y: element.y - frame.y,
});
});
});
// check needed for avoiding flickering when a key gets pressed // check needed for avoiding flickering when a key gets pressed
// during dragging // during dragging
@@ -8299,7 +8280,12 @@ class App extends React.Component<AppProps, AppState> {
transformElements( transformElements(
pointerDownState, pointerDownState,
transformHandleType, transformHandleType,
selectedElements, resizingSingleFrameOnly
? selectedElements
: this.scene.getSelectedElements({
selectedElementIds: this.state.selectedElementIds,
includeElementsInFrames: true,
}),
pointerDownState.resize.arrowDirection, pointerDownState.resize.arrowDirection,
shouldRotateWithDiscreteAngle(event), shouldRotateWithDiscreteAngle(event),
shouldResizeFromCenter(event), shouldResizeFromCenter(event),
@@ -8315,18 +8301,19 @@ class App extends React.Component<AppProps, AppState> {
) { ) {
this.maybeSuggestBindingForAll(selectedElements); this.maybeSuggestBindingForAll(selectedElements);
const elementsToHighlight = new Set<ExcalidrawElement>(); // highlight frame children ONLY when resizing a single frame
selectedFrames.forEach((frame) => { if (resizingSingleFrameOnly) {
getElementsInResizingFrame( const selectedFrame = selectedFrames[0];
this.scene.getNonDeletedElements(), if (selectedFrame) {
frame, this.setState({
this.state, elementsToHighlight: getElementsInResizingFrame(
).forEach((element) => elementsToHighlight.add(element)); this.scene.getNonDeletedElements(),
}); selectedFrame,
this.state,
this.setState({ ),
elementsToHighlight: [...elementsToHighlight], });
}); }
}
return true; return true;
} }