Skip to content

Commit 689227c

Browse files
committed
[FIX] FiguresContainer: Restrict resizing if reaches header boundary
Resizing the graph previously allowed it to go beyond the header, causing the entire graph to be pushed to the right or bottom upon release. This commit addresses this issue by introducing a restriction that prevents resizing from extending into the header. Changes made: - Added conditional checks to restrict resizing if the x or y coordinate reaches the header boundaries. closes #2726 Task: 3414127 X-original-commit: b1bac2f Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
1 parent 2438dc5 commit 689227c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/components/figures/figure_container/figure_container.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
287287
if (dirY < 0) {
288288
this.dnd.y = dndInitialY + figure.height * fraction;
289289
}
290+
291+
if (this.dnd.x < 0) {
292+
this.dnd.width += this.dnd.x;
293+
this.dnd.x = 0;
294+
}
295+
if (this.dnd.y < 0) {
296+
this.dnd.height += this.dnd.y;
297+
this.dnd.y = 0;
298+
}
290299
};
291300
} else {
292301
onMouseMove = (ev: MouseEvent) => {
@@ -301,6 +310,15 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
301310
if (dirY < 0) {
302311
this.dnd.y = dndInitialY - deltaY;
303312
}
313+
314+
if (this.dnd.x < 0) {
315+
this.dnd.width += this.dnd.x;
316+
this.dnd.x = 0;
317+
}
318+
if (this.dnd.y < 0) {
319+
this.dnd.height += this.dnd.y;
320+
this.dnd.y = 0;
321+
}
304322
};
305323
}
306324
const onMouseUp = (ev: MouseEvent) => {

tests/components/figure.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,24 @@ describe("figures", () => {
267267
expect(model.getters.getFigure(sheetId, figureId)).toMatchObject(expectedSize);
268268
});
269269

270+
test.each([
271+
["top", { mouseOffsetX: 0, mouseOffsetY: -100 }],
272+
["left", { mouseOffsetX: -100, mouseOffsetY: 0 }],
273+
["topLeft", { mouseOffsetX: -100, mouseOffsetY: -100 }],
274+
])(
275+
"Resizing a figure through its top and left anchor does not change size beyond header boundaries",
276+
async (anchor: string, mouseMove: { mouseOffsetX: number; mouseOffsetY: number }) => {
277+
const figureId = "someuuid";
278+
const sheetId = model.getters.getActiveSheetId();
279+
const figure = { width: 100, height: 100 };
280+
createFigure(model, { id: figureId, y: 0, x: 0, ...figure });
281+
await nextTick();
282+
await simulateClick(".o-figure");
283+
await dragAnchor(anchor, mouseMove.mouseOffsetX, mouseMove.mouseOffsetY, true);
284+
expect(model.getters.getFigure(sheetId, figureId)).toMatchObject(figure);
285+
}
286+
);
287+
270288
test.each([
271289
[
272290
"topLeft",

0 commit comments

Comments
 (0)