Skip to content
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

Merged
merged 2 commits into from
Mar 7, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 15, 2018

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 underlying editor 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).

@aduth aduth added the General Interface Parts of the UI which don't fall neatly under other labels. label Feb 15, 2018
@aduth aduth force-pushed the add/scroll-reorder-preserve branch 3 times, most recently from d98ba47 to 2afc4ed Compare February 26, 2018 14:04
@aduth aduth requested a review from a team February 26, 2018 14:04
*/
restorePreviousOffset() {
const { selectionStart } = this.props;
const scrollContainer = getScrollContainer( this.node );
Copy link
Contributor

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.

Copy link
Member Author

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 + '"]' );
Copy link
Contributor

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=")

Copy link
Member Author

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.

@jasmussen
Copy link
Contributor

Scroll preservation you say?

Is there any of this work that affects or might help #4775?

@aduth
Copy link
Member Author

aduth commented Feb 27, 2018

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.

@aduth aduth force-pushed the add/scroll-reorder-preserve branch from 2afc4ed to fad28e2 Compare February 27, 2018 19:47
Copy link
Contributor

@youknowriad youknowriad left a 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.

👍

@aduth aduth merged commit c20fd9c into master Mar 7, 2018
@aduth aduth deleted the add/scroll-reorder-preserve branch March 7, 2018 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Interface Parts of the UI which don't fall neatly under other labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants