Jump to a markdown heading in the preview#320
Open
jongio wants to merge 1 commit into
Open
Conversation
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]>
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.
What
Adds a heading jump list to the preview panel for markdown files. Press
ton a markdown file to open a list of its headings, navigate withj/k(or arrows,g/G,home/end), and pressEnterto scroll to the selected heading.Esccloses 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.goparses ATX headings (#through######) from the raw file source, skipping fenced code blocks so shell comments and diff hunks are not mistaken for headings.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=1passes, 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 thetkey integration on markdown vs non-markdown files.go build ./...,go vet,gofumpt -l, andgolangci-lint run ./internal/panels/preview/...are clean.KeyBindings()and mirrored ininternal/keybindings/keybindings.json;docs/keybindings.mdregenerated.