-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block List: Extract scroll preservation as non-visual component #5085
Conversation
d98ba47
to
2afc4ed
Compare
*/ | ||
restorePreviousOffset() { | ||
const { selectionStart } = this.props; | ||
const scrollContainer = getScrollContainer( this.node ); |
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.
The question I'm wondering is whether we should preserve the scrolling relatively to the scrollable parent of blockNode
or the parent of this.node
. I'm thinking maybe the most logical would be blockNode
even if it's the same node right now.
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'm thinking maybe the most logical would be
blockNode
even if it's the same node right now.
Good point. Also helps simplify the component by removing the need for any return value or node binding. Updated in rebased eb63976.
* @return {Element} Block DOM node. | ||
*/ | ||
export function getBlockDOMNode( uid ) { | ||
return document.querySelector( '[data-block="' + uid + '"]' ); |
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'm seeing two other places where we use a similar technical to get the block DOM node, should we update those as well? (search for [data-block="
)
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'm seeing two other places where we use a similar technical to get the block DOM node, should we update those as well? (search for
[data-block="
)
I could only find one other, but replaced it in fad28e2.
There's a reference to data-block
in WritingFlow
as well, but this wouldn't be as easy to replace and is proposed for removal anyways in #5289.
Scroll preservation you say? Is there any of this work that affects or might help #4775? |
No, I don't believe so, as the changes here are specific to reordering of blocks. |
2afc4ed
to
fad28e2
Compare
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 scrolling down I'm seeing a 1px difference between previous and next scroll position (I have only texts and a single image placeholder I'm moving and I'm using Firefox), but I'm also seeing the same issue on master.
👍
This pull request seeks to extract scroll offset preserving behavior from the block component to a new non-visual component, to reflect that this behavior is not inherent to a block but rather the post editor in which it is rendered.
Implementation notes:
This pull request assumes that the behavior is specific to the post editor (
edit-post
) and, as such, exposes a number of helpers which are implemented and used in the underlyingeditor
module to avoid reimplementing them.Notably, this includes a new
getBlockDOMNode
helper which, while giving me pause, seems preferable to DOM-based behaviors being stressed within the block component where they don't belong, and at least abstracts this behavior in case a future change in markup structure is made.Testing instructions:
Verify there is no regression in the behavior of preserving scroll position when rearranging a block (i.e. you should be able to repeatedly move up or down a block in a long post content).