From 56c087e79a504266353bed16794cf88c32abafac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 18 Jun 2021 13:21:48 +0200 Subject: [PATCH] Improve section links behaviour (#367) * Limit the impact of section html id changing * Make sure section links scroll to section after loading finishes --- assets/js/session/index.js | 8 ++++++++ lib/livebook_web/live/session_live/section_component.ex | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/assets/js/session/index.js b/assets/js/session/index.js index 3686114d7..c37d07968 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -472,6 +472,14 @@ function focusCellFromUrl(hook) { if (getCellById(cellId)) { setFocusedCell(hook, cellId); } + } else { + // Explicitly scroll to the target element + // after the loading finishes + const htmlId = hash.replace(/^#/, ""); + const element = document.getElementById(htmlId); + if (element) { + element.scrollIntoView(); + } } } diff --git a/lib/livebook_web/live/session_live/section_component.ex b/lib/livebook_web/live/session_live/section_component.ex index 5aa08e2ce..19a46368a 100644 --- a/lib/livebook_web/live/session_live/section_component.ex +++ b/lib/livebook_web/live/session_live/section_component.ex @@ -4,13 +4,12 @@ defmodule LivebookWeb.SessionLive.SectionComponent do def render(assigns) do ~L"""