fix: auto scroll to top in code block - #304
Merged
Merged
Conversation
Reviewer's GuideReplaces Slate's default scrollSelectionIntoView behavior with a custom implementation that avoids jump-to-top scrolling in code blocks and wires it into the editor, along with an end-to-end Playwright test for the regression. Sequence diagram for custom scrollSelectionIntoView behaviorsequenceDiagram
actor User
participant EditorEditable
participant SlateEditable
participant ReactEditor
participant scrollSelectionIntoView
participant DOMRange
participant ScrollContainer
User->>EditorEditable: Type in code block
EditorEditable->>SlateEditable: Render with scrollSelectionIntoView prop
SlateEditable->>ReactEditor: Update selection
SlateEditable->>DOMRange: Compute DOM range for selection
SlateEditable->>scrollSelectionIntoView: scrollSelectionIntoView(editor, domRange)
scrollSelectionIntoView->>DOMRange: getBoundingClientRect()
scrollSelectionIntoView->>scrollSelectionIntoView: Validate rangeRect and selection
scrollSelectionIntoView->>DOMRange: Read startContainer.parentElement as leafEl
scrollSelectionIntoView->>ScrollContainer: leafEl.closest(appflowy-scroll-container)
alt Cursor already visible
scrollSelectionIntoView-->>SlateEditable: Return without scrolling
else Cursor out of view
scrollSelectionIntoView->>leafEl: Override getBoundingClientRect
scrollSelectionIntoView->>leafEl: scrollIntoView(block=nearest)
scrollSelectionIntoView->>leafEl: Restore getBoundingClientRect
scrollSelectionIntoView-->>SlateEditable: Return after minimal scroll
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The temporary monkey-patching of
leafEl.getBoundingClientRectwould be safer if wrapped in a try/finally (or similar guard) so the override is always cleaned up even ifscrollIntoViewthrows, rather than relying on the finaldeleteline executing normally. - The use of a hard-coded
.appflowy-scroll-containerselector inscrollSelectionIntoViewcould be brittle; consider making the scroll container lookup more generic or configurable so the behavior doesn’t silently break if the container class changes or if the editor is rendered in a different scrollable context.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The temporary monkey-patching of `leafEl.getBoundingClientRect` would be safer if wrapped in a try/finally (or similar guard) so the override is always cleaned up even if `scrollIntoView` throws, rather than relying on the final `delete` line executing normally.
- The use of a hard-coded `.appflowy-scroll-container` selector in `scrollSelectionIntoView` could be brittle; consider making the scroll container lookup more generic or configurable so the behavior doesn’t silently break if the container class changes or if the editor is rendered in a different scrollable context.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
fix #300 #261
Summary by Sourcery
Prevent editor selection from causing unwanted scroll-to-top jumps in code blocks by customizing the selection scroll behavior.
Bug Fixes:
Tests: