fix text resize in extra padding

This commit is contained in:
hamid zarghami
2026-01-06 11:37:09 +03:30
parent cf8752ca76
commit 2890603c29
2 changed files with 41 additions and 33 deletions
+12 -6
View File
@@ -460,10 +460,14 @@ const EditorCanvas = () => {
height: node.y() + dy,
});
} else if (selectedObject.type === "text" || selectedObject.type === "link") {
// Text and Link: calculate actual dimensions after transform
const clientRect = node.getClientRect({ skipTransform: true });
const newWidth = clientRect.width * scaleX;
const newHeight = clientRect.height * scaleY;
// Text and Link: use stored width/height from store, not getClientRect
// because TextShape auto-calculates dimensions and we need to scale the stored values
const storedWidth = selectedObject.width || 100;
const storedHeight = selectedObject.height || 100;
// Use average scale to maintain aspect ratio for text
const avgScale = (scaleX + scaleY) / 2;
const newWidth = Math.max(5, storedWidth * scaleX);
const newHeight = Math.max(5, storedHeight * scaleY);
if (selectedObject.type === "link") {
// For link, also update fontSize
@@ -474,12 +478,14 @@ const EditorCanvas = () => {
fontSize: selectedObject.fontSize ? Math.max(5, selectedObject.fontSize * scaleX) : undefined,
});
} else {
// For text, update width, height, and fontSize
updateObject(selectedObject.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
width: Math.max(5, newWidth),
height: Math.max(5, newHeight),
width: newWidth,
height: newHeight,
fontSize: selectedObject.fontSize ? Math.max(5, selectedObject.fontSize * avgScale) : undefined,
});
}
} else {