From 40158aa6cc6675fa4261861bd72992a1f22dcccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 29 Oct 2021 15:05:59 +0200 Subject: [PATCH] Improve scroll on cell focus/blur (#659) * Stay in insert mode only if evaluate is clicked * Never scroll when focusing cell with click --- assets/js/session/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/js/session/index.js b/assets/js/session/index.js index aa02c776c..9563f3cde 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -392,13 +392,14 @@ function handleDocumentMouseDown(hook, event) { return; } - // If click targets a clickable element that awaits mouse up, keep the focus as is - if (event.target.closest(`a, button`)) { - // If the pencil icon is clicked, enter insert mode - if (event.target.closest(`[data-element="enable-insert-mode-button"]`)) { - setInsertMode(hook, true); - } + // If the pencil icon is clicked, enter insert mode + if (event.target.closest(`[data-element="enable-insert-mode-button"]`)) { + setInsertMode(hook, true); + return; + } + // If primary cell action is clicked, keep the focus as is + if (event.target.closest(`[data-element="actions"][data-primary]`)) { return; } @@ -408,7 +409,7 @@ function handleDocumentMouseDown(hook, event) { const insertMode = editableElementClicked(event, cell); if (cellId !== hook.state.focusedCellId) { - setFocusedCell(hook, cellId, !insertMode); + setFocusedCell(hook, cellId, false); } // Depending on whether the click targets editor disable/enable insert mode