From 145f8a69925dd081ffcf5554dc075412c1d4a5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 28 Dec 2021 19:42:04 +0100 Subject: [PATCH] Focus fixes (#831) --- assets/css/utilities.css | 4 ---- assets/js/cell/index.js | 15 +++++++-------- lib/livebook_web/live/session_live.ex | 2 +- lib/livebook_web/templates/layout/root.html.heex | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/assets/css/utilities.css b/assets/css/utilities.css index a4e4b6a5e..3595d6d02 100644 --- a/assets/css/utilities.css +++ b/assets/css/utilities.css @@ -27,10 +27,6 @@ transform: scaleY(-1); } - .scroll-smooth { - scroll-behavior: smooth; - } - /* Animations */ .fade-in { diff --git a/assets/js/cell/index.js b/assets/js/cell/index.js index e22a3b253..02258bf73 100644 --- a/assets/js/cell/index.js +++ b/assets/js/cell/index.js @@ -216,15 +216,14 @@ function handleInsertModeChanged(hook, insertMode) { hook.state.insertMode = insertMode; if (hook.state.liveEditor) { - // For some reason, when clicking the editor for a brief moment it is - // already focused and the cursor is in the previous location, which - // makes the browser immediately scroll there. We blur the editor, - // then wait for the editor to update the cursor position, finally - // we focus the editor and scroll if the cursor is not in the view - // (when entering insert mode with "i"). - hook.state.liveEditor.blur(); + hook.state.liveEditor.focus(); + + // The insert mode may be enabled as a result of clicking the editor, + // in which case we want to wait until editor handles the click and + // sets new cursor position. To achieve this, we simply put this task + // at the end of event loop, ensuring the editor mousedown handler is + // executed first setTimeout(() => { - hook.state.liveEditor.focus(); scrollIntoView(document.activeElement, { scrollMode: "if-needed", behavior: "smooth", diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 62325aad8..de60cd870 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -119,7 +119,7 @@ defmodule LivebookWeb.SessionLive do <.runtime_info data_view={@data_view} session={@session} socket={@socket} empty_default_runtime={@empty_default_runtime} /> -
+
- + @@ -10,7 +10,7 @@ - + <%= @inner_content %>