fix(muya): keep a hard line break's glyph on the line it ends (#2094) by Jocs · Pull Request #5556 · marktext/marktext · GitHub
Skip to content

fix(muya): keep a hard line break's glyph on the line it ends (#2094) - #5556

Merged
Jocs merged 1 commit into
developfrom
fix/2094-hard-line-break-glyph-wrap
Sep 25, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/2094-hard-line-break-glyph-wrap

Conversation

@Jocs

@Jocs Jocs commented Sep 25, 2026

Copy link
Copy Markdown
Member

Closes #2094.

The bug

A line ending in two spaces (a hard line break) shows a ↩ marker. When the
line's text reaches the right margin, the marker wraps onto the next line by
itself
, so the paragraph grows by a whole line of empty-looking space. The
reporter's example still reproduces in the current engine: the text sits on
line 1, ↩ alone on line 2, and the text after the break on line 3.

Why

.mu-hard-line-break-space holds the two literal spaces and generated the
marker as its ::after. Under white-space: pre-wrap, preserved trailing
spaces hang over the margin — but only while nothing follows them on the
line. Generated content after them revokes the hang and needs width of its
own, so the break opportunity at the spaces is taken and the marker lands
alone on the next line.

Measured in Chromium against the real engine: the failure covers an ~18px band
of column widths (the width of the two spaces plus the marker), at every one of
which the paragraph is one line taller than the same text with a soft break.

Taking the marker out of flow as an ::after is not enough — its
static position still sits after the spaces, so ~half the band remains. The
marker has to be generated ahead of the spaces to leave them last on the
line.

The fix

Generate the marker as an out-of-flow ::before and paint it past the spaces
with inset-inline-start: 100% (logical, so RTL is unchanged — verified). The
spaces keep hanging, the text wraps exactly as it would with no marker shown,
and the marker renders where it always did. A marker no longer inflates the
line box either, so a hard break now costs exactly what a soft break costs.

Tests

packages/muya/e2e/tests/inline/hard-line-break-wrap-2094.spec.ts sweeps the
text column across 400 widths and asserts, at every one:

  • the paragraph is never taller than the same text with a soft line break
    (the issue's stated expectation), and
  • the marker is still painted on the line it ends (a screenshot of the first
    line differs from the soft-break control's).

Both fail on develop (the first over an 18px band) and pass here. Also
verified in the packaged app: the same sweep over --editor-area-width fails
before the change and passes after it.

🤖 Generated with Claude Code

Preserved trailing spaces hang over the right margin only while nothing
follows them on the line. The `↩` marker was generated after them, so it
both revoked the hang and asked for width a full line had none of: a line
whose text reached the margin pushed the marker alone onto the next line,
costing a whole line of vertical space.

Generate it as an out-of-flow `::before` instead — ahead of the spaces in
the inline flow, painted past them at `inset-inline-start: 100%`. The
spaces keep hanging, the text wraps exactly as it would with no marker
shown, and the marker stays where it was.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Jocs
Jocs merged commit 7fa72e7 into develop Sep 25, 2026
7 checks passed
@Jocs
Jocs deleted the fix/2094-hard-line-break-glyph-wrap branch September 25, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

newline glyph consumes entire line

1 participant