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 23 additions and 36 deletions

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;
} }

View File

@@ -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);
} }
}; };

View File

@@ -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,