fix: address code review findings from crop/text commit

- CropOverlay: register move/up handlers dynamically on drag start (single
  handler instead of 8x per-handle), remove on drag end. Override destroy()
  to call _cleanup() preventing keyboard listener leaks.
- Text format toolbar: re-measure text bounds (w/h) after fontSize/fontFamily
  changes, update spatial index and transform box.
- TextEditor: add clearText() method; tools.ts uses it instead of fragile
  document.querySelector('textarea').
- SceneManager._updateItem: apply crop mask on remote sync for image items.
- useCanvasSetup: stop TextEditor on unmount to prevent orphaned textarea.
- Double-click zoom: use item.data dimensions instead of getBounds() (which
  includes shadow offset).
This commit is contained in:
Hiren Kangad
2026-03-11 17:28:52 +05:30
parent 58da934ec1
commit 01f22c9d43
6 changed files with 72 additions and 21 deletions
+7 -5
View File
@@ -132,15 +132,16 @@ export function useCanvasSetup(deps: CanvasSetupDeps) {
// Double-click image: zoom-to-fit (PureRef-style focus)
selection.onDoubleClickImage = (item) => {
const bounds = item.displayObject.getBounds();
const padding = 80; // screen pixels of padding around the image
const screenW = viewport.screenWidth;
const screenH = viewport.screenHeight;
const scaleX = (screenW - padding * 2) / bounds.width;
const scaleY = (screenH - padding * 2) / bounds.height;
const bw = item.data.w * Math.abs(item.data.sx);
const bh = item.data.h * Math.abs(item.data.sy);
const scaleX = (screenW - padding * 2) / bw;
const scaleY = (screenH - padding * 2) / bh;
const targetScale = Math.min(scaleX, scaleY, 3); // cap at 3x
const cx = item.data.x + (item.data.w * item.data.sx) / 2;
const cy = item.data.y + (item.data.h * item.data.sy) / 2;
const cx = item.data.x + bw / 2;
const cy = item.data.y + bh / 2;
viewport.animate({
time: 300,
position: { x: cx, y: cy },
@@ -442,6 +443,7 @@ export function useCanvasSetup(deps: CanvasSetupDeps) {
laserCleanupRef.current = null;
dropCleanupRef.current?.();
pasteCleanupRef.current?.();
textEditorRef.current?.stopEditing(false);
if (cropOverlayRef.current) {
cropOverlayRef.current.destroy();
cropOverlayRef.current = null;