Skip to content

Jump to a markdown heading in the preview#320

Open
jongio wants to merge 1 commit into
mainfrom
idea/markdown-heading-jump
Open

Jump to a markdown heading in the preview#320
jongio wants to merge 1 commit into
mainfrom
idea/markdown-heading-jump

Conversation

@jongio

@jongio jongio commented Jul 12, 2026

Copy link
Copy Markdown
Owner

What

Adds a heading jump list to the preview panel for markdown files. Press t on a markdown file to open a list of its headings, navigate with j/k (or arrows, g/G, home/end), and press Enter to scroll to the selected heading. Esc closes the list without moving the viewport.

Closes #316

Why

Navigating a long README or design doc in the preview meant scrolling by hand to find a section. This gives a quick keyboard path to any heading, matching the existing goto-line (L) workflow.

How

  • internal/panels/preview/toc.go parses ATX headings (# through ######) from the raw file source, skipping fenced code blocks so shell comments and diff hunks are not mistaken for headings.
  • When markdown rendering is on (the default), glamour strips the leading hashes during rendering, so the raw heading line no longer matches the displayed line. Each raw heading is mapped forward onto its rendered line by matching the ansi-stripped heading text in document order. With rendering off, the raw line index maps directly.
  • The overlay reuses the panel input lifecycle (PreviewInputStartedMsg) already used by goto-line, and is guarded off for binary, large, diff, blame, and GitHub views.

Testing

  • go test ./internal/panels/preview/ -count=1 passes, including new tests for heading parsing (fenced-code skipping, closing-hash stripping, rejection of non-headings), display-line mapping against real glamour output, overlay activation guards, key navigation, and the t key integration on markdown vs non-markdown files.
  • go build ./..., go vet, gofumpt -l, and golangci-lint run ./internal/panels/preview/... are clean.
  • Keybinding registered in the panel KeyBindings() and mirrored in internal/keybindings/keybindings.json; docs/keybindings.md regenerated.

Reading a long markdown file in the preview panel meant scrolling by hand
to reach a section. Press "t" on a markdown file to open a heading list,
move the selection with j/k (or the arrows, g/G, home/end), and press
Enter to scroll straight to that heading. Esc closes the list without
moving the viewport.

Headings are parsed from the raw source so fenced code blocks are skipped.
When markdown rendering is on (the default), the rendered display strips
the leading hashes, so each raw heading is mapped forward onto its rendered
line by matching the ansi-stripped heading text in document order. With
rendering off the raw line index is used directly.

Closes #316

Co-authored-by: Copilot App <[email protected]>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 12, 2026
@jongio jongio self-assigned this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jump to a markdown heading in the preview

1 participant