What happened?
In a right-to-left document, putting the caret on an empty paragraph does not
place it on the start of the line. It sits a space width inside the line.
Expected: the caret sits on the line start, which in RTL is the right edge of
the line box, the same place the first typed character will appear.
Actual: it sits ~4.4px to the left of it at Arial 16px, and the gap is
proportional to the font size, so it grows with zoom and with larger text.
Steps to reproduce
- Open a Hebrew (or any RTL) document, or set a paragraph to right-to-left.
- Type a line of text, press Enter.
- Look at the caret on the new empty line: it is not on the right edge where
the text will start.
SuperDoc version
2.10.0 (@superdoc/docx-engine 0.9.0)
Browser
Chrome
Additional context
renderLine paints an empty line with a superdoc-empty-run span that carries
the line's PM positions, filled with
(packages/layout-engine/painters/dom/src/runs/render-line.ts). A non-breaking
space has a real advance width, and the caret for an empty line is drawn at the
placeholder's left edge. On an LTR line that edge is the line start, so nothing
shows; on an RTL line the line starts at the right edge, so the caret lands one
space width inside it.
Measured on a Hebrew document, Arial 16px, empty paragraph after a line of text:
|
x |
| line box right edge (= line start, RTL) |
697.7 |
.superdoc-empty-run box |
693.3 → 697.7 |
| caret |
693.3 |
Two checks that the placeholder's advance is what moves the caret, both done
from the page with CSS only:
.superdoc-empty-run { letter-spacing: 20px } → the box widens to
673.3 → 697.7 and the caret moves to 673.3. It tracks the box.
- placeholder given zero advance → the caret lands on 697.7, the line start,
and its height is unchanged.
A fix is up in #3950: fill the placeholder with a zero-width space, which keeps
the span's font metrics (and the caret's height) while contributing no advance.
What happened?
In a right-to-left document, putting the caret on an empty paragraph does not
place it on the start of the line. It sits a space width inside the line.
Expected: the caret sits on the line start, which in RTL is the right edge of
the line box, the same place the first typed character will appear.
Actual: it sits ~4.4px to the left of it at Arial 16px, and the gap is
proportional to the font size, so it grows with zoom and with larger text.
Steps to reproduce
the text will start.
SuperDoc version
2.10.0 (
@superdoc/docx-engine0.9.0)Browser
Chrome
Additional context
renderLinepaints an empty line with asuperdoc-empty-runspan that carriesthe line's PM positions, filled with
(
packages/layout-engine/painters/dom/src/runs/render-line.ts). A non-breakingspace has a real advance width, and the caret for an empty line is drawn at the
placeholder's left edge. On an LTR line that edge is the line start, so nothing
shows; on an RTL line the line starts at the right edge, so the caret lands one
space width inside it.
Measured on a Hebrew document, Arial 16px, empty paragraph after a line of text:
.superdoc-empty-runboxTwo checks that the placeholder's advance is what moves the caret, both done
from the page with CSS only:
.superdoc-empty-run { letter-spacing: 20px }→ the box widens to673.3 → 697.7 and the caret moves to 673.3. It tracks the box.
and its height is unchanged.
A fix is up in #3950: fill the placeholder with a zero-width space, which keeps
the span's font metrics (and the caret's height) while contributing no advance.