Skip to content

fix: renumber only the code blocks an edit changes - #682

Merged
Azganoth merged 1 commit into
mainfrom
bug/code-line-numbers
Oct 10, 2026
Merged

Azganoth merged 1 commit into
mainfrom
bug/code-line-numbers

Conversation

@Azganoth

Copy link
Copy Markdown
Owner

Summary

While code line numbers were shown, every document change rebuilt the line-number decorations of every code block in one new DecorationSet, which costs top-level blocks times decorations. Typing anywhere in a document with much code slowed with the square of its code, as highlighting did before #678.

  • fix: highlight only the code blocks an edit changes #678's incremental update moves out of the highlight plugin into a shared codeBlockDecorations utility, and both plugins use it: the set is built once, then each transaction maps it and decorates again only the code blocks in its changed ranges, plus every code block inside a node whose own boundary it changed. Highlighting behaves as before.
  • With line numbers shown, an edit outside code does no numbering work and an edit inside a block renumbers only that block. Turning the setting on still numbers every block, and turning it off clears them.
  • docs/architecture.md describes the line numbers alongside the incremental highlighting, and the existing CHANGELOG.md entry for faster typing in code-heavy documents now covers line numbers.

Related Issue

Closes #679

Verification

  • Focused tests compare the line-number decorations with a full rebuild after edits inside, between, and across code blocks, splits and joins, conversions between code and paragraph, wrapping in and lifting out of a quote, whole-document replacement, and toggling the setting with edits in between, and they assert which blocks are renumbered. Rebuilding the whole set, skipping the removal of stale decorations, or skipping the code blocks inside a node whose boundary changed each makes them fail. The highlight tests pass unchanged through the shared utility.
  • pnpm check:frontend passed.

Manually verified in a happy-dom test mount on Windows 11, with a temporary probe that was not committed:

  1. The fixture was about 1 MB of fenced code: roughly 1,030 30-line excerpts of the repository's TypeScript, Rust, and CSS, each after a one-sentence paragraph. Each keystroke's transaction was applied to the editor state seven times at the end of the middle paragraph and seven times inside the middle code block.

    Keystroke main at fa9e842 This branch
    Paragraph, line numbers shown 163–476 ms 9–19 ms
    Code block, line numbers shown 158–182 ms 9–12 ms
    Either, line numbers hidden 6–24 ms 6–14 ms

Not verified: keystroke times in a release build.

@Azganoth Azganoth added the Bug Something isn't working label Oct 10, 2026
@Azganoth Azganoth self-assigned this Oct 10, 2026
@Azganoth
Azganoth merged commit 33016d8 into main Oct 10, 2026
3 checks passed
@Azganoth
Azganoth deleted the bug/code-line-numbers branch October 10, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Every edit rebuilds the line-number decorations of all code blocks

1 participant