From 2642fc61c66d862097381081474f6cc4652ecbf0 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Fri, 28 Aug 2026 10:44:39 +0000 Subject: [PATCH] fix: a floating text box lands inside the column at first paint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit applyWrap computed the right float's margin from the wrapper width, which fitWrapper only sets once the ResizeObserver has measured the mounted rotor — at construction it read 0, shoving the box its whole width off the column until the next node update (a click) re-ran it. The margin now falls back to the attr size through the rotation math, and the observer re-applies the wrap after each refit. --- src/lib/editor/extensions/textBox.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/editor/extensions/textBox.ts b/src/lib/editor/extensions/textBox.ts index a5840cf..dab31bb 100644 --- a/src/lib/editor/extensions/textBox.ts +++ b/src/lib/editor/extensions/textBox.ts @@ -364,6 +364,8 @@ class TextBoxView { this.observer = new ResizeObserver(() => { this.applyShapeInset(); this.fitWrapper(); + // A right float's margin is computed from the wrapper width just set. + this.applyWrap(); }); this.observer.observe(this.rotor); @@ -487,6 +489,18 @@ class TextBoxView { this.contentDOM.style.padding = inset; } + // The wrapper's width before the ResizeObserver has measured the mounted rotor: + // the attr size through the same rotation math (a construction-time margin computed + // with 0 shoved a right float its whole width off the column). + private wrapperWidth(): number { + const set = parseFloat(this.dom.style.width); + if (set) return set; + const a = this.attrs(); + const rad = (a.rotation * Math.PI) / 180; + const w = a.width || DEFAULT_WIDTH_PX; + return Math.abs(w * Math.cos(rad)) + Math.abs((a.height || 0) * Math.sin(rad)); + } + // Size the wrapper to the rotor's rotated bounding box so surrounding text // reserves the right space (same math as ImageView.applyLayout). private fitWrapper(): void { @@ -512,7 +526,7 @@ class TextBoxView { d.style.margin = frameMargins('topBottom', a.wrap === 'topBottom' ? a.wrapOffset : null, 0); if (a.wrap === 'left' || a.wrap === 'right') { d.style.float = a.wrap; - d.style.margin = frameMargins(a.wrap, a.wrapOffset, parseFloat(d.style.width) || 0, null, a.wrapDist); + d.style.margin = frameMargins(a.wrap, a.wrapOffset, this.wrapperWidth(), null, a.wrapDist); } else if (a.wrap === 'topBottom') { d.style.clear = 'both'; } else if (a.wrap === 'through') {