fix: correct outline active heading detection and scroll-to-center on click#1070
Open
octo-patch wants to merge 1 commit intocodexu:devfrom
Open
fix: correct outline active heading detection and scroll-to-center on click#1070octo-patch wants to merge 1 commit intocodexu:devfrom
octo-patch wants to merge 1 commit intocodexu:devfrom
Conversation
… click (fixes codexu#1039) When scrolling, the outline panel was iterating headings forward and returning the first heading above the viewport instead of the last (most recently passed) heading. This caused the highlight to always show the topmost heading rather than the one currently visible. Also fixed scrollToHeading to use scrollIntoView({ block: 'center' }) so the selected heading is centered in the editor rather than appearing at the bottom edge of the visible area. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #1039
Problem
Two bugs in the outline panel:
Wrong active heading highlight on scroll: The
findActiveHeadingByScrollfunction iterated headings from first to last, returning the first heading whose position was at or above the viewport. With multiple headings scrolled past, this always returned the topmost heading instead of the most recently passed one, causing the highlight to be out of sync with the actual scroll position.Heading not centered when clicked: Clicking a heading in the outline used
editor.commands.scrollIntoView(), which only guarantees the selection is visible (often placing it at the bottom edge of the viewport) rather than centering it.Solution
Changed
findActiveHeadingByScrollto iterate in reverse order (last to first) so it returns the last heading whose top is at or above the viewport — i.e., the heading the user is currently reading.Changed
scrollToHeadingto usedomNode.scrollIntoView({ behavior: 'smooth', block: 'center' })so the target heading is scrolled to the center of the editor viewport.Testing