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

Visual Editor: Keep the block at the same position while moving it #463

Merged
merged 2 commits into from
Apr 20, 2017

Conversation

youknowriad
Copy link
Contributor

closes #161

Nothing too fancy here. I'm using the lifecycle methods to save the scroll position before the update and restore it after.

@youknowriad youknowriad added the Framework Issues related to broader framework topics, especially as it relates to javascript label Apr 20, 2017
@youknowriad youknowriad self-assigned this Apr 20, 2017
@jasmussen
Copy link
Contributor

Works great! Thumbs up from a UX perspective 👍

class VisualEditorBlock extends wp.element.Component {
constructor() {
super( ...arguments );
this.bindBlockNode = this.bindBlockNode.bind( this );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function need to be bound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes?

window.scrollX,
window.scrollY + this.node.getBoundingClientRect().top - this.previousOffset
);
this.previousOffset = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using false as an empty state. Could we assign to null, undefined, or even delete this.previousOffset instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, do you have a preference for one over another? delete ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, do you have a preference for one over another? delete ?

Sorta ties into a question on whether we want to be extremely clear about the existence of the instance property by initializing it either in the constructor or as an instance initializer (I don't recall if this is a spec feature or one of the staged ones).

As it is here without initialization, I'd say delete is most appropriate.
Otherwise, if we were to initialize, probably initialize to null and reset to null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go for initialization :)

this.props.isSelected &&
newProps.isSelected
) {
this.previousOffset = this.node.getBoundingClientRect().top;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it have been possible to simply store window.scrollY here and restore it directly in the DidUpdate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually we don't want to keep the same scrollY since the block is moving, we want the block to show in the same position.

onDeselect();
const { onChange, onSelect, onDeselect, onMouseEnter, onMouseLeave, onInsertAfter } = this.props;

function setAttributes( attributes ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're making this a proper class, these might ought to be proper member functions now.

}

export default connect(
( state, ownProps ) => ( {
order: state.blocks.order.findIndex( uid => ownProps.uid === uid ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't enabled the polyfill, so this will error in IE11. We might just consider enabling the polyfill, but in this case couldn't this just be:

order: state.blocks.order.indexOf( ownProps.uid )

@youknowriad youknowriad merged commit 3bba830 into master Apr 20, 2017
@youknowriad youknowriad deleted the update/scroll-when-moving branch April 20, 2017 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: Moving block should scroll window with the block
3 participants