🐛 Fixed scroll jump in editor when pasting a url onto a selection to create a link

closes https://github.com/TryGhost/Ghost/issues/10090

- when mobiledoc-kit replaces the selection the caret window selection is temporarily set to the whole editor element which was causing our scroll-cursor-into-view routine to scroll incorrectly
- adding the guard allows the first replacement cursor change to be ignored but the second cursor change to be picked up which will do nothing if the text is on-screen, or scroll if it's off screen as normal
This commit is contained in:
Kevin Ansfield 2020-03-07 20:23:23 +00:00
parent 7ca85838c8
commit a32e7c0b65
1 changed files with 10 additions and 0 deletions

View File

@ -1228,6 +1228,16 @@ export default Component.extend({
return;
}
// start/endContainer matching editor element means the window range is
// outside of a text element so we don't want to scroll incorrectly
// (happens when replacing a selection with a link on paste)
if (windowRange &&
windowRange.startContainer === this.editor.element &&
windowRange.endContainer === this.editor.element
) {
return;
}
if (windowRange) {
// cursorTop is relative to the window rather than document or scroll container
let {top: cursorTop, height: cursorHeight} = windowRange.getBoundingClientRect();