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 { SubtypeOf } from "../utility-types";
import { getShortcutKey } from "../utils";
import { ActionName, CustomActionName } from "./types";
import { ActionName } from "./types";
export type ShortcutName =
| SubtypeOf<
ActionName,
| CustomActionName
| "toggleTheme"
| "loadScene"
| "clearCanvas"
@@ -41,15 +40,6 @@ export type ShortcutName =
| "saveScene"
| "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[]> = {
toggleTheme: [getShortcutKey("Shift+Alt+D")],
saveScene: [getShortcutKey("CtrlOrCmd+S")],

View File

@@ -35,11 +35,7 @@ type ActionFn = (
export type UpdaterFn = (res: ActionResult) => void;
export type ActionFilterFn = (action: Action) => void;
export const makeCustomActionName = (name: string) =>
`custom.${name}` as CustomActionName;
export type CustomActionName = `custom.${string}`;
export type ActionName =
| CustomActionName
| "copy"
| "cut"
| "paste"

View File

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