From 5381d05d5d9cfd6969c5684690ec589bddf8a488 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 1 Oct 2026 14:53:02 +1300 Subject: [PATCH] Fix bugtracker #266: undoing a resize to zero width did nothing Resizing a selection in the element editor down to zero width or height could not be undone: ScalePartsCommand scales back from the new rect, and a flat rect cannot be scaled from, so undo silently left the shapes collapsed and the flattening was saved. The same flat rect made deltaForRoundScaling() divide 0 by 0 and fill the resize rect with NaN. Never commit a resize rect with no width or height, and do not resize a selection that is already flat. Co-Authored-By: Claude Opus 5.5 --- sources/editor/elementprimitivedecorator.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sources/editor/elementprimitivedecorator.cpp b/sources/editor/elementprimitivedecorator.cpp index e74280b53..3b678a7d4 100644 --- a/sources/editor/elementprimitivedecorator.cpp +++ b/sources/editor/elementprimitivedecorator.cpp @@ -527,6 +527,12 @@ void ElementPrimitiveDecorator::handlerMouseMoveEvent(QetGraphicsHandlerItem *qg { Q_UNUSED(qghi); + // A selection with no width or height cannot be scaled (see + // scaleItems()); resizing it would only record a bogus undo step. + if (!original_bounding_rect_.width() || !original_bounding_rect_.height()) { + return; + } + QPointF scene_pos = event -> scenePos(); QPointF movement = scene_pos - latest_pos_; @@ -564,8 +570,15 @@ void ElementPrimitiveDecorator::handlerMouseMoveEvent(QetGraphicsHandlerItem *qg movement = rounded_scene_pos - current_position; } + QRectF scaled_rect = modified_bounding_rect_; + applyMovementToRect(current_operation_square_, movement, scaled_rect); + // A rect with no width or height cannot be scaled back from, so the + // resize could never be undone: keep the last usable size instead. + if (!scaled_rect.width() || !scaled_rect.height()) { + return; + } QRectF bounding_rect = modified_bounding_rect_; - applyMovementToRect(current_operation_square_, movement, modified_bounding_rect_); + modified_bounding_rect_ = scaled_rect; if (modified_bounding_rect_ != bounding_rect) { adjustEffectiveBoundingRect(); }