mirror of
https://github.com/penpot/penpot.git
synced 2026-11-16 15:11:17 +00:00
🐛 Keep the pages panel scroll when switching pages (#13004)
Switching pages swaps the workspace content for a loader until the new page is ready, so the whole left sidebar mounts again. The pages list started at the top and the selected page scrolled into view at the bottom of the panel, even when it was already visible. The sidebar scroll store now lives in workspace-inner*, which stays mounted across page switches. The pages panel saves its scroll there and restores it before the selected page scrolls into view. The layers, assets and tokens panels keep their positions across page switches too. Closes #13002 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
bb4556b705
commit
b2c4b58b27
@ -54,7 +54,7 @@
|
||||
|
||||
(mf/defc workspace-content*
|
||||
{::mf/private true}
|
||||
[{:keys [file layout page wglobal]}]
|
||||
[{:keys [file layout page wglobal scroll-store]}]
|
||||
|
||||
(let [palete-size (mf/use-state nil)
|
||||
selected (mf/deref refs/selected-shapes)
|
||||
@ -123,6 +123,7 @@
|
||||
:file-id (get file :id)
|
||||
:page-id page-id
|
||||
:file file
|
||||
:scroll-store scroll-store
|
||||
:selected selected
|
||||
:section options-mode
|
||||
:drawing-tool (get drawing :tool)}])]))
|
||||
@ -173,9 +174,14 @@
|
||||
(mf/defc workspace-inner*
|
||||
{::mf/private true}
|
||||
[{:keys [page-id file-id file layout wglobal]}]
|
||||
(let [page-ref (mf/with-memo [file-id page-id]
|
||||
(make-page-ref file-id page-id))
|
||||
page (mf/deref page-ref)]
|
||||
(let [page-ref (mf/with-memo [file-id page-id]
|
||||
(make-page-ref file-id page-id))
|
||||
page (mf/deref page-ref)
|
||||
|
||||
;; NOTE: lives here because the sidebar unmounts on every page
|
||||
;; switch (the loader replaces `workspace-content*` until the
|
||||
;; new page is ready), so the scroll positions must outlive it
|
||||
scroll-store* (mf/use-var {})]
|
||||
|
||||
(mf/with-effect []
|
||||
(let [focus-out #(st/emit! (dw/workspace-focus-lost))
|
||||
@ -191,7 +197,8 @@
|
||||
[:> workspace-content* {:file file
|
||||
:page page
|
||||
:wglobal wglobal
|
||||
:layout layout}]
|
||||
:layout layout
|
||||
:scroll-store scroll-store*}]
|
||||
[:> workspace-loader*])))
|
||||
|
||||
(mf/defc workspace*
|
||||
|
||||
@ -101,6 +101,7 @@
|
||||
[:article {:class (stl/css :layers-tab)}
|
||||
[:> sitemap* {:layout layout
|
||||
:height sitemap-height
|
||||
:scroll-store scroll-store
|
||||
:collapsed sitemap-collapsed?
|
||||
:on-toggle-collapsed on-toggle-sitemap-collapsed}]
|
||||
|
||||
@ -118,11 +119,10 @@
|
||||
|
||||
(mf/defc left-sidebar*
|
||||
{::mf/memo true}
|
||||
[{:keys [layout file tokens-lib tokens-status active-tokens resolved-active-tokens]}]
|
||||
[{:keys [layout file tokens-lib tokens-status active-tokens resolved-active-tokens scroll-store]}]
|
||||
(let [options-mode (mf/deref refs/options-mode-global)
|
||||
project (mf/deref refs/project)
|
||||
file-id (get file :id)
|
||||
scroll-store* (mf/use-var {})
|
||||
|
||||
design-tokens? (features/use-feature "design-tokens/v1")
|
||||
mode-inspect? (= options-mode :inspect)
|
||||
@ -216,7 +216,7 @@
|
||||
:assets
|
||||
[:> assets-toolbox* {:size (- width 58)
|
||||
:file-id file-id
|
||||
:scroll-store scroll-store*}]
|
||||
:scroll-store scroll-store}]
|
||||
|
||||
:tokens
|
||||
[:> tokens-sidebar-tab*
|
||||
@ -224,12 +224,12 @@
|
||||
:tokens-status tokens-status
|
||||
:active-tokens active-tokens
|
||||
:resolved-active-tokens resolved-active-tokens
|
||||
:scroll-store scroll-store*}]
|
||||
:scroll-store scroll-store}]
|
||||
|
||||
:layers
|
||||
[:> layers-content* {:layout layout
|
||||
:width width
|
||||
:scroll-store scroll-store*}])]])]]))
|
||||
:scroll-store scroll-store}])]])]]))
|
||||
|
||||
;; --- Right Sidebar (Component)
|
||||
|
||||
@ -362,7 +362,7 @@
|
||||
[:> options-toolbox* props]))]]]]))
|
||||
|
||||
(mf/defc sidebar*
|
||||
[{:keys [layout file file-id page-id section drawing-tool selected]}]
|
||||
[{:keys [layout file file-id page-id section drawing-tool selected scroll-store]}]
|
||||
(let [tokens-lib
|
||||
(mf/deref refs/tokens-lib)
|
||||
|
||||
@ -407,6 +407,7 @@
|
||||
[:> left-sidebar* {:layout layout
|
||||
:file file
|
||||
:page-id page-id
|
||||
:scroll-store scroll-store
|
||||
:tokens-lib tokens-lib
|
||||
:tokens-status tokens-status
|
||||
:active-tokens active-tokens-force-set
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
(ns app.main.ui.workspace.sidebar.scroll
|
||||
"Scroll position save/restore for sidebar panels.
|
||||
|
||||
Panels unmount on every tab switch, so positions that must survive it
|
||||
cannot live in component state. The store is created once in
|
||||
`left-sidebar*` (which stays mounted while tabs swap, unlike
|
||||
`layers-content*` and the toolboxes) with `mf/use-var` and threaded to
|
||||
the panels as a prop. Shape: {[panel id] scroll-top}."
|
||||
Panels unmount on every tab switch, and the whole sidebar unmounts on
|
||||
every page switch, so positions that must survive it cannot live in
|
||||
component state. The store is created once in `workspace-inner*` (which
|
||||
stays mounted while pages and tabs swap) with `mf/use-var` and threaded
|
||||
to the panels as a prop. Shape: {[panel id] scroll-top}."
|
||||
(:require
|
||||
[app.util.dom :as dom]
|
||||
[app.util.timers :as tm]
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
[app.main.ui.ds.foundations.assets.icon :as i :refer [icon*]]
|
||||
[app.main.ui.hooks :as hooks]
|
||||
[app.main.ui.notifications.badge :refer [badge-notification]]
|
||||
[app.main.ui.workspace.sidebar.scroll :as sc]
|
||||
[app.render-wasm.api :as wasm.api]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
@ -291,10 +292,16 @@
|
||||
;; --- Sitemap Toolbox
|
||||
|
||||
(mf/defc sitemap*
|
||||
[{:keys [height collapsed on-toggle-collapsed]}]
|
||||
[{:keys [height collapsed on-toggle-collapsed scroll-store]}]
|
||||
(let [file (mf/deref ref:file-with-pages)
|
||||
file-id (get file :id)
|
||||
project-id (get file :project-id)
|
||||
content-ref (mf/use-ref nil)
|
||||
|
||||
on-scroll (mf/use-fn
|
||||
(mf/deps scroll-store file-id)
|
||||
(fn [event]
|
||||
(sc/save-scroll! scroll-store [:sitemap file-id] event)))
|
||||
|
||||
on-create (mf/use-fn
|
||||
(mf/deps file-id project-id)
|
||||
@ -306,6 +313,15 @@
|
||||
read-only? (mf/use-ctx ctx/workspace-read-only?)
|
||||
permissions (mf/use-ctx ctx/permissions)]
|
||||
|
||||
;; NOTE: a layout effect, so the saved position is back before the
|
||||
;; selected page item runs its `scroll-into-view-if-needed!` effect.
|
||||
;; With nothing saved the list is left alone, so the selected page
|
||||
;; still scrolls into view when the file opens.
|
||||
(mf/with-layout-effect [file-id collapsed]
|
||||
(when-not ^boolean collapsed
|
||||
(when-some [saved (get @scroll-store [:sitemap file-id])]
|
||||
(sc/restore-scroll! (mf/ref-val content-ref) saved))))
|
||||
|
||||
[:div {:class (stl/css :sitemap)
|
||||
:style {:--height (dm/str height "px")}}
|
||||
|
||||
@ -326,6 +342,8 @@
|
||||
:icon i/add}])]
|
||||
|
||||
(when-not ^boolean collapsed
|
||||
[:div {:class (stl/css :sitemap-content)}
|
||||
[:div {:class (stl/css :sitemap-content)
|
||||
:ref content-ref
|
||||
:on-scroll on-scroll}
|
||||
[:> pages-list* {:key (dm/str (:id file))
|
||||
:file file}]])]))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user