Skip to content

[Bug] A trailing soft line break renders one blank line too many until you type #5282

Closed

Description

@Jocs

Description

A Shift+Enter soft line break renders one blank line too many until something is typed on the new line. Everything below the paragraph is pushed down by a line, and jumps back up as soon as the first character lands.

The cause is the quick-insert hint's ::after, not the line break itself:

.mu-show-quick-insert-hint .mu-paragraph.mu-active > .mu-paragraph-content:first-of-type::after {
    content: attr(placeholder);
}

placeholder is only set while the quick-insert menu is open (ui/paragraphQuickInsertMenu/index.ts:80, removed again at :82). The rest of the time the declaration resolves to an empty string — but the ::after box is still generated, and an empty box still takes part in layout. A block ending in a soft line break ends with the block-level mu-line-end span, which an inline box cannot share a line with, so the hint claims a line of its own.

Not IME-specific: plain ASCII typing reproduces it. Long-standing — it predates #5281, which only made it easy to notice (before that a CJK IME overwrote the newline on the first keystroke, taking the spurious line with it).

Steps to Reproduce

  1. Open a new document and enter two paragraphs:

    第一行
    
    第二段
  2. Put the caret at the end of 第一行.

  3. Press Shift+Enter — 第二段 is pushed down by one line.

  4. Type any character — 第二段 jumps back up.

Expected Behavior

A block whose text ends with \n occupies two lines: the text, and one empty line holding the caret. The content below it does not move when the line break is inserted, and does not move again when the next character is typed.

Actual Behavior

The block occupies three lines between step 3 and step 4 — one empty line holds the caret, and a second empty line sits below it with nothing in it.

Measured against the muya E2E host (one line = 26px there; a desktop build will differ in absolute numbers):

paragraph height next paragraph starts at
第一行 (one-line reference) 26px 101
after Shift+Enter 77px 152
after typing one character (two-line reference) 51px 126

77px where 51px is correct — exactly one extra line.

Screenshots / Logs

The pseudo-element is the whole difference. Same markup, same page, two containers:

container height
class="mu-content" 51px (2 lines)
class="mu-content mu-paragraph-content" 77px (3 lines)

mu-paragraph-content appears in exactly one stylesheet rule, the quick-insert hint above. With that one pseudo-element disabled the paragraph measures 51px, the caret node keeps its geometry (top=93 h=26, i.e. still on the visible empty line), and typing still produces 第一行\na. Its computed content outside the quick-insert menu is "" — an empty box that still occupies a line.

Child boxes after Shift+Enter, with the paragraph running to y=144 and nothing in 119–144:

<span.mu-plain-text>              "第一行"  top=68  h=22   line 1
<span.mu-soft-line-break.mu-line-end> "\n"  top=93  h=26   line 2 (display: block)
                                                    …119–144 empty, line 3, no node in it
Earlier, incorrect diagnosis — kept for the record

This was first read as mu-line-end's block box and the \n inside it each contributing a line, because removing either one gives the correct height:

height
as shipped 77px (3 lines)
keep the mu-line-end block, empty the \n inside it 51px (2 lines)
keep the \n, drop mu-line-end (span goes inline) 51px (2 lines)

Both of those work by removing the block box the ::after cannot sit beside, so they relieve the symptom without touching the cause — and both break something else (emptying the \n desynchronises the DOM text that getTextContent / getOffsetOfParagraph rebuild the model and offsets from; making the span inline puts the caret at the end of the previous line and makes typing insert before the newline). Several CSS variants on .mu-line-end were tried on that basis and all failed; font-size: 0 looked correct on height, typing and IME, but collapsed the caret's node to zero height at y=93 while the visible empty line sat at y≈119.

Operating System

macOS

MarkText Version

0.20.0-dev (develop @ 6402160e)

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue

Activity

  1. added
    🐛 bug
    🚧 needs triage
    on Sep 10, 2026
  2. Jocs commented on Sep 10, 2026

    @Jocs
    MemberAuthor

    Correcting the root cause above. The first reading — mu-line-end's block box and the \n inside it each contributing a line — was wrong. It came from observing that removing either one gives the correct height, which is true but only because both remove the block box the hint's ::after cannot sit beside.

    Putting the same markup in two containers in the same page isolates it: class="mu-content" measures 51px, class="mu-content mu-paragraph-content" measures 77px. mu-paragraph-content appears in exactly one rule — the quick-insert hint's ::after, whose selector does not require the placeholder attribute it reads. Outside the quick-insert menu that attribute is absent, so the declaration resolves to an empty string while the box is still generated and still takes a line.

    The original diagnosis is kept in a collapsed section for the record, along with the CSS variants tried on that basis and why each failed.

    Fix in #5283 — one selector, gated on the attribute.

  3. added a commit that references this issue on Sep 10, 2026
    af1ded1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bug🔭 area/muya🚧 needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions