From 04edc75181a09babc50a604eab99b6a326c8e22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 20 Apr 2021 19:31:23 +0200 Subject: [PATCH] Scroll to section when moved (#226) --- assets/js/session/index.js | 5 ++--- lib/livebook_web/live/session_live.ex | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/assets/js/session/index.js b/assets/js/session/index.js index a8e4c954b..f1ff748dd 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -509,9 +509,8 @@ function handleSectionDeleted(hook, sectionId) { } function handleSectionMoved(hook, sectionId) { - if (hook.state.focusedSectionId === sectionId) { - globalPubSub.broadcast("session", { type: "section_moved", sectionId }); - } + const section = getSectionById(sectionId); + smoothlyScrollToElement(section); } function handleCellUpload(hook, cellId, url) { diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 69a6bb497..8bcfe3287 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -459,6 +459,14 @@ defmodule LivebookWeb.SessionLive do end end + defp after_operation(socket, _prev_socket, {:move_section, client_pid, section_id, _offset}) do + if client_pid == self() do + push_event(socket, "section_moved", %{section_id: section_id}) + else + socket + end + end + defp after_operation(socket, _prev_socket, _operation), do: socket defp handle_actions(socket, actions) do