From 98e0f66c596c25b7c5b742c8d1ff315704e3e522 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Sat, 7 Mar 2020 20:23:23 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20scroll=20jump=20in=20edi?= =?UTF-8?q?tor=20when=20pasting=20a=20url=20onto=20a=20selection=20to=20cr?= =?UTF-8?q?eate=20a=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../koenig-editor/addon/components/koenig-editor.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js index fbe395f6e1..4def64d92f 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js @@ -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();