Skip to content

Commit 8befdcc

Browse files
authored
fix(app): remember the vertical tabs sidebar's width (#68275)
1 parent 1b10653 commit 8befdcc

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎packages/app/src/shell/shell.tsx‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { createPanelMotion, guardClosingFocus, panelOpacity, setPanelResizing } from "@/shell/panel-motion"
2727
import { createSidebarPeek } from "@/shell/sidebar-peek"
2828
import { windowDragEnabled } from "@/session/header/drag-area"
29+
import { useLayout } from "@/shell/state/layout"
2930

3031
type SidebarPose = { closed: number; peek: number | undefined }
3132

@@ -135,19 +136,18 @@ function MainShell(props: ParentProps) {
135136
const command = useCommand()
136137
const language = useLanguage()
137138
const dialog = useDialog()
139+
const layout = useLayout()
138140
const mobile = createMediaQuery("(max-width: 767px)")
139141

140142
createTipToasts()
141143

142144
useDeepLinks()
143145

144146
const [state, setState] = createStore<{
145-
tabsWidth: number
146147
tabsMount: HTMLElement | undefined
147148
tabsAside: HTMLElement | undefined
148149
tabsPanel: HTMLElement | undefined
149150
}>({
150-
tabsWidth: 240,
151151
tabsMount: undefined,
152152
tabsAside: undefined,
153153
tabsPanel: undefined,
@@ -213,17 +213,18 @@ function MainShell(props: ParentProps) {
213213
sidebar.closed = closed
214214
const aside = state.tabsAside
215215

216-
if (aside) aside.style.width = `${state.tabsWidth * (1 - closed)}px`
216+
if (aside) aside.style.width = `${layout.tabsSidebar.width() * (1 - closed)}px`
217217

218218
// Dims the contents, background included, as they leave and brightens them as they arrive.
219219
paintSidebarContents()
220220
paintCollapsedSlots(closed)
221221
},
222222
// The contents slide by their own width, which a peek widens past the docked sidebar's.
223-
measure: () => measureSidebarToggles((state.tabsMount?.offsetWidth ?? state.tabsWidth) * sidebarHidden()),
223+
measure: () =>
224+
measureSidebarToggles((state.tabsMount?.offsetWidth ?? layout.tabsSidebar.width()) * sidebarHidden()),
224225
// A dock from a peek already shows the sidebar, so reduced motion has nothing to fade in.
225226
element: () => (peek.handedOff() ? undefined : state.tabsPanel),
226-
distance: () => state.tabsWidth,
227+
distance: () => layout.tabsSidebar.width(),
227228
})
228229

229230
const peek = createSidebarPeek({
@@ -330,8 +331,8 @@ function MainShell(props: ParentProps) {
330331
data-peek={peek.shown() ? "" : undefined}
331332
style={{
332333
"--sidebar-peek-width": peek.shown()
333-
? `calc(${state.tabsWidth}px + var(--shell-inline-inset, 8px))`
334-
: `${state.tabsWidth}px`,
334+
? `calc(${layout.tabsSidebar.width()}px + var(--shell-inline-inset, 8px))`
335+
: `${layout.tabsSidebar.width()}px`,
335336
}}
336337
ref={(element) => setState("tabsAside", element)}
337338
class="relative z-10 h-full min-h-0 shrink-0"
@@ -375,10 +376,10 @@ function MainShell(props: ParentProps) {
375376
<Show when={preferences.appearance.sidebarOpen()}>
376377
<ResizeHandle
377378
direction="horizontal"
378-
size={state.tabsWidth}
379+
size={layout.tabsSidebar.width()}
379380
min={136}
380381
max={640}
381-
onResize={(width) => setState("tabsWidth", width)}
382+
onResize={layout.tabsSidebar.resize}
382383
onDraggingChange={setPanelResizing}
383384
/>
384385
</Show>

‎packages/app/src/shell/state/layout.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe("layout persistence", () => {
6565
expect(current.fileTree).toEqual({ opened: true, width: 260, tab: "all" })
6666
})
6767

68+
test("keeps the vertical tabs sidebar's width apart from the legacy sidebar's", () => {
69+
const value = decode({ sidebar: { width: 420 }, tabsSidebarWidth: 320 })
70+
expect(value.tabsSidebarWidth).toBe(320)
71+
expect(decode(Schema.encodeSync(schema)(value)).tabsSidebarWidth).toBe(320)
72+
expect(decode({ sidebar: { width: 420 } }).tabsSidebarWidth).toBeUndefined()
73+
expect(decode({ tabsSidebarWidth: "bad" }).tabsSidebarWidth).toBeUndefined()
74+
})
75+
6876
test("distinguishes an invalid panel field from an invalid review section", () => {
6977
const fileTree = { opened: true, tab: "all" }
7078
expect(decode({ review: { panelOpened: "bad" }, fileTree }).review.panelOpened).toBe(true)

‎packages/app/src/shell/state/layout.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747

4848
const DEFAULT_SIDEBAR_WIDTH = 344
4949

50+
const DEFAULT_TABS_SIDEBAR_WIDTH = 240
51+
5052
const DEFAULT_FILE_TREE_WIDTH = 200
5153

5254
const DEFAULT_SESSION_WIDTH = 600
@@ -177,6 +179,9 @@ export const layoutSchema = Persistence.struct({
177179
session: Persistence.struct({ width: Schema.Finite }),
178180
// The side region's width per panel (`${plugin}:${panel id}`) that sizes itself, app-wide.
179181
panelWidths: Schema.optional(Persistence.record(Schema.Finite)),
182+
// The vertical tabs sidebar's width. `sidebar.width` belonged to the legacy sidebar; layouts still carry its stale
183+
// value, so it is not reused.
184+
tabsSidebarWidth: Schema.optional(Schema.Finite),
180185
mobileSidebar: Persistence.struct({ opened: Schema.Boolean }),
181186
sessionTabs: Persistence.record(Persistence.fallback(sessionTabsSchema, () => ({ all: [] }))),
182187
sessionView: Persistence.record(Persistence.fallback(sessionViewSchema, () => ({ scroll: {} }))),
@@ -586,6 +591,12 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
586591
setStore("panelWidths", panel, width)
587592
},
588593
},
594+
tabsSidebar: {
595+
width: createMemo(() => store.tabsSidebarWidth ?? DEFAULT_TABS_SIDEBAR_WIDTH),
596+
resize(width: number) {
597+
setStore("tabsSidebarWidth", width)
598+
},
599+
},
589600
mobileSidebar: {
590601
opened: createMemo(() => store.mobileSidebar?.opened ?? false),
591602
hide() {

0 commit comments

Comments
 (0)