Scroll to section when moved (#226)

This commit is contained in:
Jonatan Kłosko 2021-04-20 19:31:23 +02:00 committed by GitHub
parent 44eda43d02
commit 04edc75181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -509,9 +509,8 @@ function handleSectionDeleted(hook, sectionId) {
} }
function handleSectionMoved(hook, sectionId) { function handleSectionMoved(hook, sectionId) {
if (hook.state.focusedSectionId === sectionId) { const section = getSectionById(sectionId);
globalPubSub.broadcast("session", { type: "section_moved", sectionId }); smoothlyScrollToElement(section);
}
} }
function handleCellUpload(hook, cellId, url) { function handleCellUpload(hook, cellId, url) {

View file

@ -459,6 +459,14 @@ defmodule LivebookWeb.SessionLive do
end end
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 after_operation(socket, _prev_socket, _operation), do: socket
defp handle_actions(socket, actions) do defp handle_actions(socket, actions) do