fix
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user