Skip to content

[Bug] Code block line numbers are missing on empty lines #5294

Closed

Description

@Jocs

Description

With code block line numbers turned on, empty lines in a code block don't get a visible line number. The number for an empty line is placed above the code block, outside the visible area. Numbers positioned after it are lost too, and when a block starts with empty lines their numbers pile up on the first row.

Steps to Reproduce

  1. Open Preferences → Editor and enable Whether to show the line numbers.
  2. In a document, type ``` and press Enter to create a code block.
  3. Type hello, press Enter twice, then type world.

Other empty-line layouts show the same problem:

  • Type hello and press Enter twice (empty lines at the end).
  • In an empty code block press Enter twice, then type hello (empty lines at the top).
  • With Wrap text inside code blocks on, type a line long enough to wrap and press Enter at its end.

Expected Behavior

Every line shows its number next to it, empty or not:

1  hello
2
3  world

Actual Behavior

  • hello / empty / world: the gutter shows 1 and 3; 2 is missing (drawn about 4 lines above the block).
  • hello + Enter + Enter: only 1 is shown; 2 and 3 are missing.
  • Enter + Enter + hello: 1 and 2 overlap on the first row, and 3 is drawn below the block.
  • Wrapped long line + Enter: 2 sits on the wrapped line's second row instead of on the new empty line.

Screenshots / Logs

Reproduced on develop (19faab1) in the @muyajs/core e2e host (Chromium), which runs the same engine as the desktop editor. Gutter for hello / empty / world:

1  hello

3  world

Cause: repositionLineNumberSpans in packages/muya/src/utils/codeBlockLineNumbers.ts positions each number from the rect of a collapsed Range at the line's first character. On an empty line that position has no client rects, so Chromium returns an all-zero rect. The number then gets top = 0 - firstLineTop (−99px in the report above). Measured for a\n\nb:

collapsed range at each line start   top 3.0 | (no rect) | 49.1
range over the empty line's "\n"     top 26.0
gutter span style.top                0px | -98.98px | 46.09px

The empty line after a final newline has no text position at all. It is stacked one line-height below the previous number, which is wrong when the previous line wraps.

Operating System

macOS

MarkText Version

0.20.0-dev (develop @ 19faab1)

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue

Activity

  1. added
    🐛 bug
    🚧 needs triage
    on Sep 10, 2026
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🚧 needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions