Repository navigation
feat(desktop): reveal the active file in the sidebar file tree (#528) - #5654
Conversation
|
Website preview ready: https://pr-5654-marktext-website.ransixi.workers.dev Built from |
1637099 to
365b97f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unknown targets mutate collapse state, and reveals are not retried when the active row arrives asynchronously.
2 open findings
What changed in this PR
Adds automatic and manual sidebar reveal for the active file, including preferences, localization, documentation, and tests.
Changes:
- Expands ancestor folders and scrolls the active file into view.
- Adds “Show in Side Bar,” a command, and an
autoRevealInSidebarpreference. - Adds unit and end-to-end coverage.
| File | Description |
|---|---|
packages/website/content/docs/end-user/PREFERENCES.md |
Documents the preference. |
packages/desktop/test/unit/specs/sidebar-reveal-path.spec.ts |
Tests ancestor expansion. |
packages/desktop/test/unit/specs/reveal-tree-row.spec.ts |
Tests scroll calculations. |
packages/desktop/test/e2e/sidebar-auto-reveal-528.spec.ts |
Tests reveal workflows. |
packages/desktop/test/e2e/helpers.ts |
Adds project-opening helper. |
packages/desktop/static/preference.json |
Adds the default preference. |
packages/desktop/static/locales/zh-TW.json |
Adds Traditional Chinese strings. |
packages/desktop/static/locales/zh-CN.json |
Adds Simplified Chinese strings. |
packages/desktop/static/locales/tr.json |
Adds Turkish strings. |
packages/desktop/static/locales/ru.json |
Adds Russian strings. |
packages/desktop/static/locales/pt.json |
Adds Portuguese strings. |
packages/desktop/static/locales/nl.json |
Adds Dutch strings. |
packages/desktop/static/locales/ko.json |
Adds Korean strings. |
packages/desktop/static/locales/ja.json |
Adds Japanese strings. |
packages/desktop/static/locales/fr.json |
Adds French strings. |
packages/desktop/static/locales/es.json |
Adds Spanish strings. |
packages/desktop/static/locales/en.json |
Adds English strings. |
packages/desktop/static/locales/de.json |
Adds German strings. |
packages/desktop/src/shared/types/preferences.ts |
Extends preference types. |
packages/desktop/src/renderer/src/util/revealTreeRow.ts |
Calculates reveal scrolling. |
packages/desktop/src/renderer/src/store/treeCtrl.ts |
Expands ancestor folders. |
packages/desktop/src/renderer/src/store/project.ts |
Exposes reveal actions. |
packages/desktop/src/renderer/src/store/preferences.ts |
Adds renderer preference state. |
packages/desktop/src/renderer/src/prefComponents/general/index.vue |
Adds the settings toggle. |
packages/desktop/src/renderer/src/contextMenu/tabs/menuItems.ts |
Defines the context-menu item. |
packages/desktop/src/renderer/src/contextMenu/tabs/index.ts |
Inserts the menu item. |
packages/desktop/src/renderer/src/contextMenu/tabs/actions.ts |
Dispatches manual reveals. |
packages/desktop/src/renderer/src/components/sideBar/treeFile.vue |
Registers rendered rows. |
packages/desktop/src/renderer/src/components/sideBar/tree.vue |
Coordinates expansion and scrolling. |
packages/desktop/src/renderer/src/components/sideBar/rowRegistry.ts |
Defines the row registry. |
packages/desktop/src/renderer/src/commands/index.ts |
Adds the reveal command. |
packages/desktop/src/renderer/src/commands/descriptions.ts |
Maps its localized description. |
packages/desktop/src/main/preferences/schema.json |
Validates the preference. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| watch( | ||
| () => editorStore.currentFile?.pathname, | ||
| (pathname) => { | ||
| revealPath(pathname) | ||
| }, | ||
| { flush: 'post' } |
There was a problem hiding this comment.
Reproduced and fixed. The failing case is common, not exotic: MarkText restores the last session (folder + tabs) and the side bar tree is filled by the watcher after currentFile is set, so the one-shot reveal ran against an empty tree and never retried. Same for "open the folder I am working in" while a file is already active.
Fix: the project store now exposes a treeVersion counter bumped for every structural tree event (add / addDir / unlink / unlinkDir — in-place mutations are invisible to watchers), and the reveal watcher depends on it together with currentFile.pathname, so each delivery is a new chance to reveal. Added an e2e test for exactly this ordering (file active → folder opened): it failed before the fix and passes now.
| const chain: TreeFolder[] = [] | ||
| let currentFolder: TreeFolder = tree | ||
| let currentSubFolders: TreeFolder[] = tree.folders | ||
| for (const directoryName of subDirectories) { | ||
| const childFolder = currentSubFolders.find((f) => f.name === directoryName) | ||
| if (!childFolder) return null | ||
| childFolder.isCollapsed = false | ||
| chain.push(childFolder) | ||
| currentFolder = childFolder | ||
| currentSubFolders = childFolder.folders | ||
| } | ||
|
|
||
| const isTracked = currentFolder.files.some((f) => | ||
| window.fileUtils.isSamePathSync(f.pathname, pathname) | ||
| ) | ||
| return isTracked ? chain : null |
There was a problem hiding this comment.
Correct, fixed. expandAncestors now walks the chain without touching it, verifies the leaf is in the deepest folder, and only then clears isCollapsed, so a failed reveal no longer changes the collapse state. Covered by a unit test asserting the folders stay collapsed for an untracked path.
Open a document in a deep folder, collapse that folder, switch to another file and back: there was no way to find it again. The title bar shows the path but is not navigable, while Atom, IntelliJ and VS Code all reveal the active file in their project tree. Reveal it the way VS Code's Explorer does for `explorer.autoReveal`: - expand only the folders leading to the file, never collapsing anything, and only once the file is known to be in the tree; - scroll only when the row is not already fully visible, then centre it, using the same formula as `ListWidget.reveal(index, 0.5)`; - leave the caret, the tree selection and `activeItem` alone, so F2 and Delete keep acting on what the user picked; - do nothing while the file list is off screen, and retry as the tree fills in, so a project opened or restored after that file is revealed as well. A single watcher on `currentFile` plus the tree's change counter drives it, so every existing way of switching files — tab click, cycle, quick open, sidebar click, startup restore — gets the behaviour without touching those call sites. Moving the folder collapse state onto the tree node (#5632) is what lets the store expand ancestors before the render instead of racing freshly mounted folder components. Also adds `autoRevealInSidebar` (on by default), a "Show in Side Bar" tab context-menu entry and a `file.reveal-in-sidebar` command for the manual case, with unit tests for the expansion and scroll maths and an e2e spec that drives the real app against a generated project.
365b97f to
4ef39d4
Compare

Closes #528
Summary
Opening a document that lives in a deep folder, collapsing that folder and then switching back to the tab left no way to find the file: the title bar shows the path but is not navigable. Atom, IntelliJ and VS Code all reveal the active file in their project tree, so the side bar now does the same, following VS Code's
explorer.autoReveal:ListWidget.reveal(index, 0.5);activeItemalone, so F2 and Delete keep acting on what the user picked;A single watcher on
currentFiledrives it, so every existing way of switching files — tab click, cycle, quick open, side bar click, startup restore — gets the behaviour without touching those call sites. It builds on #5632 (merged): keeping the folder collapse state on the tree node is what lets the store expand ancestors before the render instead of racing freshly mounted folder components.The reveal also has manual entry points: Show in Side Bar in a tab's context menu and a
file.reveal-in-sidebarcommand. Both ignore the preference, bring the file list into view and expand the collapsed Directories section. A newautoRevealInSidebarpreference (Boolean, defaulttrue) turns the automatic behaviour off, wired throughstatic/preference.json, the main-process schema, the renderer store, the General → Sidebar settings pane, all 12 locales and the preferences doc.Type of change
Test plan
New tests added:
test/unit/specs/reveal-tree-row.spec.ts— centring above/below the viewport, clamping at both ends,relativeTop0/1, zero-height viewport, rows taller than the viewport, already-visible rows.test/unit/specs/sidebar-reveal-path.spec.ts— expands only the ancestor chain, keeps sibling folders collapsed, is idempotent, returnsnullfor project-external/unknown paths, and covers the store'sREVEAL_PATH.test/e2e/sidebar-auto-reveal-528.spec.ts— real build against a generated project with 25 files in one folder so the list overflows: switching to a tab re-expands its folders, marks the row.currentand scrolls it into view; a row that is already visible leavesscrollTopat 0; withautoRevealInSidebar: falseswitching tabs does not touch the tree; and Show in Side Bar re-opens a collapsed side bar and reveals the file anyway.test/e2e/helpers.tsgainsopenProjectFolder, which both side bar e2e specs use to open a fixture folder in the running window.Manually tested on: macOS
Also run locally:
pnpm run typecheck,pnpm run lint(0 errors), the unit suite, and the full desktop Playwright suite — 346 passed / 3 failed / 5 skipped, the 3 failures (find-replace regex, i18n-shell, parity-cursor-lang) reproducing identically ondevelop.Notes for reviewers
activeItem, so it cannot retarget F2/Delete; the file tree already marks the active row with its.currentstyle.pnpm run minify-localesmust run before production builds, as usual for locale changes.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.