Skip to content

fix: #5152 align TOC navigation with editor viewport - #5153

Draft
foo-hao wants to merge 1 commit into
marktext:developfrom
foo-hao:agent/fix-toc-heading-offset
Draft

fix: #5152 align TOC navigation with editor viewport#5153
foo-hao wants to merge 1 commit into
marktext:developfrom
foo-hao:agent/fix-toc-heading-offset

Conversation

@foo-hao

@foo-hao foo-hao commented Aug 19, 2026

Copy link
Copy Markdown

Closes #5152

Summary

  • Align TOC targets relative to the editor scroll container instead of a fixed window coordinate.
  • Keep 24 CSS pixels of clearance between the revealed heading and the editor viewport.
  • Cover the scroll calculation, a visible two-tab layout, repeated TOC navigation, and heading anchor links.

Root cause

TOC navigation shared the fixed STANDAR_Y viewport coordinate used for caret-oriented scrolling. Window chrome such as the tab bar moves the editor viewport without changing that coordinate, so headings could either land far down the document or become obscured when the constant was reduced.

User impact

Clicking a TOC entry now places the heading near the editor's visible top edge with consistent clearance across layouts, including windows with multiple tabs.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New unit and end-to-end regression tests added
  • Manually verified on macOS 26.5.2
  • corepack pnpm run build
  • corepack pnpm run test:unit — 50 files, 736 tests passed
  • corepack pnpm -C packages/desktop exec playwright test test/e2e/toc-scroll.spec.ts test/e2e/anchor-link-scroll.spec.ts — 6 tests passed
  • corepack pnpm run typecheck
  • corepack pnpm run lint

Demonstration

With two documents open, clicking Heading Number 18 keeps the full heading visible below the tab bar:

TOC navigation with two visible tabs

Notes for reviewers

The TOC uses a dedicated container-relative calculation. Search highlights and non-heading anchors continue using their existing caret-oriented reveal position.


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TOC navigation uses a fixed viewport offset

1 participant