-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: autoscroll when block is bigger than viewport #3746
Changes from all commits
af9faf0
6178862
bbad026
db3b47b
95a235d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate-react': patch | ||
--- | ||
|
||
Fix editor auto-scrolling behavior when a block is bigger than the viewport. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,10 +205,14 @@ export const Editable = (props: EditableProps) => { | |
) | ||
} | ||
const leafEl = newDomRange.startContainer.parentElement! | ||
leafEl.getBoundingClientRect = newDomRange.getBoundingClientRect.bind( | ||
newDomRange | ||
) | ||
scrollIntoView(leafEl, { | ||
scrollMode: 'if-needed', | ||
boundary: el, | ||
}) | ||
delete leafEl.getBoundingClientRect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 this throws a typescript error could you elaborate why this is needed @gztomas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juliankrispel this restores the override happening at line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for explaining @gztomas |
||
} else { | ||
domSelection.removeAllRanges() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when testing this fix, did you scroll around a lot? Worried about performance issues when building and destroying this every time you scroll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found any performance issues so far. If that was the case however I think we would see the issue on typing rather than on scrolling given this piece of code is only called when the selection changes, not the scroll. I believe this should be a cheap operation either way. Or at least probably cheaper than the DOM access operations that happen on
toDOMRange
sequential to this.