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

EZP-28773: [v2] Issues with page scrolling during actions in rich text editor #801

Merged
merged 2 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bundle/Resources/public/js/alloyeditor/dist/ezBtnEmbed.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/bundle/Resources/public/js/alloyeditor/dist/ezBtnImage.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export default class EzBtnEmbed extends EzEmbedDiscoverContentButton {
addEmbed(items) {
const contentInfo = items[0].ContentInfo.Content._id;

this.execCommand();
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;

this.execCommand();
window.scroll(window.pageXOffset, scrollY);
} else {
this.execCommand();
}
this.setContentInfo(contentInfo);

const widget = this.getWidget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ export default class EzBtnImage extends EzEmbedImageButton {
addImage(items) {
const content = items[0].ContentInfo.Content;

this.execCommand();
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;

this.execCommand();
window.scroll(window.pageXOffset, scrollY);
} else {
this.execCommand();
}

this.setContentInfo(content._id);

const widget = this.getWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default class EzBtnLinkEdit extends Component {
this.state.element.setAttribute(
'href', 'ezlocation://' + items[0].id
);
this.focusEditedLink();
this.invokeWithFixedScrollbar(() => {
this.focusEditedLink();
});

ReactDOM.unmountComponentAtNode(udwContainer);
};
Expand Down Expand Up @@ -299,7 +301,10 @@ export default class EzBtnLinkEdit extends Component {
} else if (event.keyCode === 27) {
const editor = this.props.editor.get('nativeEditor');
new CKEDITOR.Link(editor).advanceSelection();
editor.fire('actionPerformed', this);

this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}
}

Expand Down Expand Up @@ -351,7 +356,9 @@ export default class EzBtnLinkEdit extends Component {

this.props.cancelExclusive();

editor.fire('actionPerformed', this);
this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}

/**
Expand Down Expand Up @@ -386,14 +393,34 @@ export default class EzBtnLinkEdit extends Component {
linkAttrs.href = this.state.linkHref;
linkUtils.update(linkAttrs, this.state.element, modifySelection);

editor.fire('actionPerformed', this);
this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}

// We need to cancelExclusive with the bound parameters in case the
// button is used inside another component in exclusive mode (such
// is the case of the link button)
this.props.cancelExclusive();
}

/**
* Saves current scrollbar position, invokes callback function and scrolls
* to the saved position afterward.
*
* @method invokeWithFixedScrollbar
* @param {Function} callback invoked after saving current scrollbar position
*/
invokeWithFixedScrollbar(callback) {
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;

callback();
window.scroll(window.pageXOffset, scrollY);
} else {
callback();
}
}
}

AlloyEditor.Buttons[EzBtnLinkEdit.key] = AlloyEditor.ButtonLinkEdit = EzBtnLinkEdit;