From 9c052d39d47055444bc03a48abadc9134a27e951 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Mon, 17 Jul 2023 18:23:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9D=20Fix=20#2518?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/components/CellInput.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/frontend/components/CellInput.js b/frontend/components/CellInput.js index e3a57c6421..9133b305a2 100644 --- a/frontend/components/CellInput.js +++ b/frontend/components/CellInput.js @@ -631,17 +631,23 @@ export const CellInput = ({ // Remove selection on blur EditorView.domEventHandlers({ blur: (event, view) => { - // collapse the selection into a single point - view.dispatch({ - selection: { - anchor: view.state.selection.main.head, - }, - scrollIntoView: false, - }) - // and blur the DOM again (because the previous transaction might have re-focused it) - view.contentDOM.blur() - - set_cm_forced_focus(null) + // it turns out that this condition is true *exactly* if and only if the blur event was triggered by blurring the window + let caused_by_window_blur = document.activeElement === view.contentDOM + + if (!caused_by_window_blur) { + // then it's caused by focusing something other than this cell in the editor. + // in this case, we want to collapse the selection into a single point, for aesthetic reasons. + view.dispatch({ + selection: { + anchor: view.state.selection.main.head, + }, + scrollIntoView: false, + }) + // and blur the DOM again (because the previous transaction might have re-focused it) + view.contentDOM.blur() + + set_cm_forced_focus(null) + } }, }), pluto_paste_plugin({