Repository navigation
fix(session-ui): scroll Markdown fragment links to their heading - #59550
Merged
Merged
Conversation
Contributor
Author
There was a problem hiding this comment.
The fix works. Your new browser test fails on the base (the fragment link still opens with target="_blank") and passes with this change, along with the rest of markdown.spec.ts (37). The fragment-link and parser unit tests pass, and tsc is clean for session-ui and ui. The user-content- fallback matches the sanitizer's existing SANITIZE_NAMED_PROPS setting.
Public API: unchanged. The new functions are internal to session-ui, and the marked-base link output changes only for #… links.
No blocking concerns. The new tests are small, and the browser test waits with expect.poll, not sleeps.
Fixes #57971
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.
Clicking a
#headinglink in a Markdown preview (file viewer, and Markdown in messages) did nothing: the link was rendered as an externaltarget="_blank"link, headings carry no ids, and the desktop window-open handler drops renderer URLs.marked-base: fragment-only links render as plain in-page links (noexternal-linkclass,target, or link icon).setupFragmentLinkson the Markdown root: on click it resolves the fragment against that document only — headings by their GitHub-style slug (repeats as-1,-2), then sanitized raw HTMLid/name(user-content-prefix) — and scrolls the nearest scroll container to it. The app URL and hash never change, and a missing target is a no-op instead of a navigation.scrollIntoView, which also scrolled a clipped ancestor in the file panel and pushed the Preview/Source toolbar up ~12px.Testing
bun testfor slugging/target lookup and the parser output.[Host services](#host-services)and a repeated-heading link#usage-1lands each heading at the top of the scroller without changing the URL; fails without the fix.markdown.spec.tscomponent suite passes (37).dynamic-modules.md-style table: the link scrolls to the "Host services" heading and the toolbar stays put.Visual
Requested by: @Brendonovich (Brendan via Slack)
Added by the opencode bot (AI-generated).
Fixes #57971