Skip to content

fix(desktop): keep sidebar width + tree collapse state across icon toggle - #4769

Merged
Jocs merged 2 commits into
developfrom
fix/2421-sidebar-state
Jun 27, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/2421-sidebar-state

Conversation

@Jocs

@Jocs Jocs commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary

Toggling the sidebar via its left-column icons lost UI state (#2421). Two distinct bugs, one atomic commit each:

  1. Width reset — collapsing the sidebar to its icon strip by clicking the active icon overwrote the persisted width with the clamped 220px minimum. handleLeftIconClick read finalSideBarWidth after setting rightColumn='', when that computed already returns the 45px icon-strip width → CHANGE_SIDE_BAR_WIDTH(45) clamps to 220. Re-expanding then restored 220, shrinking a widened sidebar. Fix: capture the expanded width before collapsing.
  2. Collapse state reset — the "Opened files" / "Directories" section collapse lived in local refs in tree.vue, which is rendered under v-if and destroyed when the sidebar collapses, so the sections reset to expanded on re-open (Ctrl+J uses v-show, so it didn't). Fix: back the state with localStorage (same convention as the sidebar width), so it survives the re-mount and app restart (also requested in the issue comments).

Reproduction & verification (real app)

Added issue-2421-sidebar-state.spec.ts, a Playwright/Electron e2e against the built app. Both tests were RED on the current code and GREEN after the fixes:

  • drag-widen → collapse via icon → re-expand: width was reset by ~120px (340→220), now preserved within 3px.
  • collapse the "Opened files" section → toggle the sidebar off/on: section reset to expanded, now stays collapsed.

The existing layout-toggles.spec.ts (4 tests, incl. the editor-fills-width-after-collapse case) still passes; lint + vue-tsc clean.

Fixes #2421

Jocs and others added 2 commits June 27, 2026 15:29
Collapsing the sidebar to its icon strip by clicking the active left-column
icon overwrote the persisted width with the clamped 220px minimum: it read
finalSideBarWidth AFTER setting rightColumn to '', when that computed already
evaluates to the 45px icon strip. Re-expanding then restored 220px, losing a
widened sidebar. Capture the expanded width before collapsing.

Refs #2421

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The "Opened files" / "Directories" collapse state lived in local refs in
tree.vue, which is rendered under a v-if and destroyed when the sidebar
collapses to its icon strip — so the sections reset to expanded on re-open.
Back the state with localStorage (like the sidebar width) so it survives the
re-mount and app restart (also requested in the issue comments).

Fixes #2421

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4769:

Run: https://github.com/marktext/marktext/actions/runs/28282581334

Artifact Size Link
marktext-windows-arm64 275.7 MB Download
marktext-linux 627.5 MB Download
marktext-macos-x64 293.0 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit 25caaba into develop Jun 27, 2026
10 checks passed
@Jocs
Jocs deleted the fix/2421-sidebar-state branch June 27, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar collapse state memory inconsistant

1 participant