From 1ff5bcfd252eafea23bccd5f12dbf00b00f98afc Mon Sep 17 00:00:00 2001 From: saqib mir Date: Fri, 12 Jun 2026 15:39:14 +0530 Subject: [PATCH] fix --- frontend/src/viewer/TextEditLayer.tsx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/viewer/TextEditLayer.tsx b/frontend/src/viewer/TextEditLayer.tsx index c1a9537..3856d57 100644 --- a/frontend/src/viewer/TextEditLayer.tsx +++ b/frontend/src/viewer/TextEditLayer.tsx @@ -97,9 +97,33 @@ export const TextEditLayer: React.FC = ({ const commit = () => { if (editing === null || committedRef.current) return; - committedRef.current = true; const run = runs[editing]; const next = value; + + if (next !== run.text) { + // Width guard: warn if new text is > 120% original width + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + let originalWidth = run.w * zoom; + let newWidth = originalWidth; + + if (ctx) { + ctx.font = `${run.fontSize * zoom}px sans-serif`; + originalWidth = ctx.measureText(run.text).width; + newWidth = ctx.measureText(next).width; + } else { + originalWidth = run.text.length; + newWidth = next.length; + } + + if (newWidth > originalWidth * 1.2) { + if (!window.confirm('Warning: The new text is significantly wider (> 120%) than the original. This might cause overlap or layout issues. Continue anyway?')) { + return; // keep editing open + } + } + } + + committedRef.current = true; setEditing(null); if (next !== run.text) onEditText?.(pageIndex, run, next); };