This commit is contained in:
saqib mir
2026-06-12 15:39:14 +05:30
parent 6678f55e46
commit 1ff5bcfd25
+25 -1
View File
@@ -97,9 +97,33 @@ export const TextEditLayer: React.FC<TextEditLayerProps> = ({
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);
};