Repository navigation
fix(muya): number empty lines in code blocks (#5294) - #5295
Merged
Merged
Conversation
repositionLineNumberSpans walked the code's text nodes and positioned each gutter span inside the same loop. Move the walk into measureLineTops, which returns the viewport top of each line, and leave repositionLineNumberSpans to place the spans relative to the first line and fill in the lines that could not be measured. No behavior change. It leaves room to fix #5294 without pushing the function past the ESLint complexity limit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014KtYifHmaETtxfX2ktbdYC
With code block line numbers on, an empty line's number was drawn above the block, below it, or on another line's row. Each number is placed at the top of a collapsed range at the start of its line. On an empty line that caret position has no client rects, so Chromium reports an all-zero rect and the number landed at minus the first line's top. Measure an empty line with a range over its own newline instead: it has a real rect with the same text-box metrics. The line after a final newline has no character to measure and was stacked one line-height under the previous number, which is the wrong row when the previous line wraps. Measure it from the trailing break CodeBlockContent renders there (#5114). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014KtYifHmaETtxfX2ktbdYC
Checks, in real Chromium, which row each gutter number sits on: an empty line typed between lines, at the end and at the top of a block, a syntax-highlighted block, and wrapped code with an empty line after a wrapped line. All six fail on develop. Adds a lineNumber selector for the gutter spans. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014KtYifHmaETtxfX2ktbdYC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5294.
With code block line numbers on, an empty code line's number was drawn above the block, below it, or on another line's row, so empty lines looked unnumbered.
Root cause
repositionLineNumberSpansplaces each gutter number at the top of a collapsed Range at the start of its line. On an empty line that caret position has no client rects in Chromium, sogetBoundingClientRect()is all zeros. The number then gottop = 0 - firstLineTop(about −99px in the e2e host). When the first line itself was empty, the origin became 0 and the following numbers moved below the block.The line after a final newline has no character to measure. It was stacked one line-height below the previous number, which puts it on the wrong row when the previous line wraps.
Fix
\n. In Chromium that range has a real rect with the same top and height as a caret on a non-empty line, so the first-line origin still cancels the line-box leading..mu-trailing-breakthatCodeBlockContentrenders there since [Bug] code block 中换行不能准确表现 #5114. Line-height stacking now only covers lines with nothing to measure, such as an empty code block.measureLineTops, with no behavior change, so the fix keepsrepositionLineNumberSpansunder the ESLint complexity limit.Tests
blocks/codeblock-line-numbers-empty-line-5294.spec.tschecks which row each number sits on. It covers an empty line between lines, empty lines at the end and at the top, a syntax-highlighted block, and wrapped code (an empty line after a wrapped line, loaded and typed). All 6 fail on develop and on the refactor commit with the same values, and pass with the fix.codeblock-trailing-newline-5114,options/code-font(gutter re-measure) andcodeblock-scroll-3191e2e still pass. ThecodeBlockLineNumbersandlineNumbersGutterunit specs pass, andtsc --noEmit, ESLint and madge are clean.Checked in Chromium only, which is what Electron and the muya e2e CI use.
🤖 Generated with Claude Code
https://claude.ai/code/session_014KtYifHmaETtxfX2ktbdYC