Repository navigation
Description
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
- Open Preferences → Editor and enable Whether to show the line numbers.
- In a document, type
```and press Enter to create a code block. - Type
hello, press Enter twice, then typeworld.
Other empty-line layouts show the same problem:
- Type
helloand 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 shows1and3;2is missing (drawn about 4 lines above the block).hello+ Enter + Enter: only1is shown;2and3are missing.- Enter + Enter +
hello:1and2overlap on the first row, and3is drawn below the block. - Wrapped long line + Enter:
2sits 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
fix(muya): number empty lines in code blocks (marktext#5294) (marktex…