Skip to content

fix(desktop): compare sidebar and tab paths across separator styles (#5683) - #5689

Merged
Jocs merged 1 commit into
developfrom
fix/5683-sidebar-folder-native-path-separators
Oct 10, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/5683-sidebar-folder-native-path-separators

Conversation

@Jocs

@Jocs Jocs commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Closes #5683

Summary

On Windows, renaming or deleting a folder left the old folder row in the sidebar, and deleting a folder failed with Error invoking remote method 'mt::fs-trash-item': Error: Failed to parse path.

The sandboxed renderer's window.path shim is pathe, which always uses /, while the watcher, the main process and the Electron shell APIs use OS-native separators (\ on Windows). Comparing those paths with === silently missed matches, so the watcher's unlinkDir/unlink never removed the renderer-built folder node, and the / path was rejected by Windows' shell.trashItem (SHCreateItemFromParsingName).

This restores the Windows tree behavior that #728 fixed; the sandbox migration replaced node's path with pathe (#4244, #4274) and regressed it. The fix:

  • compares sidebar/tab paths with the existing preload isSamePathSync helper (separator/case insensitive),
  • makes the Delete/F2 isPathWithinRoot guard separator-insensitive,
  • converts renderer / paths to the native separator at the OS shell boundary (shell.trashItem / showItemInFolder / openPath).

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
    • sidebar-windows-path-separators.spec.ts — fails before the fix (renamed/deleted folder lingers after a native-separator watcher event)
    • sidebar-new-file-native-separators.spec.ts — new-file cache matched across separators
    • native-path-shell-5683.spec.ts — toNativePath converts renderer / paths on Windows
    • sidebar-trash-key.spec.ts — mixed-separator isPathWithinRoot cases
    • issue-5683-sidebar-folder-native-separators.spec.ts (e2e) — real app: injecting the native-separator unlinkDir the watcher sends on Windows removes the folder row
    • trash-item-confirm.spec.ts updated to assert the native-normalized path so it holds on the windows-latest unit job
    • vitest run 1076 passed; sidebar e2e suite passes; pnpm run typecheck and pnpm run lint clean
  • Manually tested on:
    macOS only (no Windows host available). The Windows shape was reproduced by feeding native-separator watcher events — both at the module level with the real treeCtrl, and end-to-end in the running app (out/ built from this branch). The new unit specs also run for real on windows-latest in CI (fix(tests): Windows paths + CI + timeout fix  #5323).

Notes for reviewers [optional]

How Windows paths were handled before (the fix follows these conventions rather than adding a new one):

Known limitations / decisions:

  • The tree still stores folder nodes with / and file nodes with the watcher's native separator; this PR makes the comparisons separator-insensitive rather than forcing one style, because pathe can't emit Windows separators and the sandboxed preload can't load node:path.
  • toNativePath keeps path.win32.normalize behind an injectable sep so the Windows branch is unit-testable on any runner.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

…5683)

The sandboxed renderer's `window.path` shim is `pathe`, which always uses
`/` (#4244, #4274), while the watcher, the main process and the Electron
shell APIs use OS-native separators (`\` on Windows). Comparing those paths
with `===` silently missed matches on Windows, which broke folder
rename/delete, new-file and tab lookups, and the Delete/F2 key guards.

This restores the Windows tree behavior that #728 fixed with the native
`path.sep`; the sandbox migration replaced node's `path` with `pathe`,
regressing it.

- Compare tree paths with `isSamePathSync` so renamed/deleted folders stop
  lingering in the sidebar.
- Use the same comparison for the new-file cache, the current-file
  highlight, tab switch/save-status and rename bookkeeping.
- Make `isPathWithinRoot` separator-insensitive so Delete/F2 reach files.
- Convert renderer `/` paths to the native separator at the shell boundary
  (`shell.trashItem` / `showItemInFolder` / `openPath`), fixing the Windows
  "Failed to parse path" error. `mt::fs::*` needs no change: fs-extra
  accepts `/` on Windows.
@Jocs
Jocs force-pushed the fix/5683-sidebar-folder-native-path-separators branch from 9535a6e to ec4084c Compare October 9, 2026 11:47
@Jocs
Jocs requested a review from Tkaixiang October 9, 2026 11:59
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5689:

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

Artifact Size Link
marktext-linux 660.8 MB Download
marktext-macos-arm64 297.6 MB Download
marktext-windows-x64 296.5 MB Download
marktext-macos-x64 310.9 MB Download
marktext-windows-arm64 288.3 MB Download

@Tkaixiang

Copy link
Copy Markdown
Member
image image

Deletion and renaming works well now.

Confirmed that both fail in 0.19.2

@Jocs
Jocs merged commit 34ea993 into develop Oct 10, 2026
11 checks passed
Jocs added a commit that referenced this pull request Oct 10, 2026
Follow-up to #5689. Rather than comparing mixed-separator paths, remove the
mismatch at its source: the sandboxed preload now supplies a real Windows path
module, so the renderer builds native paths exactly like the watcher and the
main process.

- preload: `@std/path/windows` on Windows (JSR, via npm.jsr.io), `pathe` on POSIX
- electron-vite: inline `@jsr/std__path` into the preload bundle
- replace the last hardcoded `/` filesystem join (`CREATE_FILE_DIRECTORY`)
- drop the #5689 separator patches (`isSamePath` comparisons, `isPathWithinRoot`
  folding, `toNativePath`) and the specs that encoded the mixed-separator state

`platform-path-windows.spec.ts` drives the real stores with a win32 path module
and asserts renderer-built paths are byte-identical to the watcher/main paths,
so plain `===` matches — the gate for dropping the patches.
Jocs added a commit that referenced this pull request Oct 10, 2026
…5669)

Follow-up to #5689. Rather than comparing mixed-separator paths, remove the
mismatch at its source: the renderer and its preload now use a real Windows path
module, so every path they build matches the native paths from the watcher, the
main process and the OS.

- add `createPlatformPath(isWindows)` (`@jsr/std__path` win32 on Windows,
  `pathe` on POSIX) and use it for the preload's `window.path`
- alias the bare `path` specifier in the renderer build to the same platform
  path, so shared helpers like `common/envPaths` stop producing `/` paths on
  Windows
- title bar breadcrumb: split on the platform separator — fixes #5669, where a
  native `C:\…` path was split on `/` and only the filename showed
- replace the last hardcoded `/` filesystem join (`CREATE_FILE_DIRECTORY`)
- drop the #5689 separator patches (`isSamePath` comparisons, `isPathWithinRoot`
  folding, `toNativePath`) and the specs that encoded the mixed-separator state

`platform-path-windows.spec.ts` drives the real stores with a win32 path module
and asserts renderer-built paths are byte-identical to the watcher/main paths,
so plain `===` matches — the gate for dropping the patches.
Zane-0x5a added a commit to Zane-0x5a/marktext that referenced this pull request Oct 10, 2026
Takes upstream's separator-insensitive isPathWithinRoot from marktext#5689 over
the fork's UNC-aware variant: folding every run of separators to '/'
already matches a backslash UNC path against '//server/share'. The fork's
mixed-separator UNC spec goes with it.

Keeps pdfjs-dist on top of the marktext#5687 dependency upgrades, leaves
deep-equal out, and regenerates the lockfile from upstream's.
Jocs added a commit that referenced this pull request Oct 11, 2026
…5669) (#5691)

Follow-up to #5689. Rather than comparing mixed-separator paths, remove the
mismatch at its source: the renderer and its preload now use a real Windows path
module, so every path they build matches the native paths from the watcher, the
main process and the OS.

- add `createPlatformPath(isWindows)` (`@jsr/std__path` win32 on Windows,
  `pathe` on POSIX) and use it for the preload's `window.path`
- alias the bare `path` specifier in the renderer build to the same platform
  path, so shared helpers like `common/envPaths` stop producing `/` paths on
  Windows
- title bar breadcrumb: split on the platform separator — fixes #5669, where a
  native `C:\…` path was split on `/` and only the filename showed
- replace the last hardcoded `/` filesystem join (`CREATE_FILE_DIRECTORY`)
- drop the #5689 separator patches (`isSamePath` comparisons, `isPathWithinRoot`
  folding, `toNativePath`) and the specs that encoded the mixed-separator state

`platform-path-windows.spec.ts` drives the real stores with a win32 path module
and asserts renderer-built paths are byte-identical to the watcher/main paths,
so plain `===` matches — the gate for dropping the patches.
@Jocs
Jocs deleted the fix/5683-sidebar-folder-native-path-separators branch October 23, 2026 08:32
Wangqkoe pushed a commit to Wangqkoe/marktext that referenced this pull request Oct 24, 2026
…arktext#5683) (marktext#5689)

Local changes to the pick: the legacy tab lookup in editor.ts uses
isSamePath while the local workspace branch is unchanged; treeFile.vue
takes only the isSamePath import (the others belong to unpicked rename
and reveal features); the new-file cache spec sends the Folder root
identity that local tree events require.

(cherry picked from commit 34ea993)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Wangqkoe pushed a commit to Wangqkoe/marktext that referenced this pull request Oct 24, 2026
…xt#5683, marktext#5669) (marktext#5691)

Local changes to the pick:
- pnpm-lock.yaml only gains @jsr/std__path and its @jsr/std__internal
  dependency; a full install would also have moved the unpinned
  file-icons tarball and reshuffled eslint peer entries.
- Keeps the local @intlify/core-base version.
- Drops the marktext#5689 isSamePath comparisons in the local editor.ts workspace
  fallback and project.ts as upstream does; treeFile.vue needs none of the
  unpicked rename/row-registry imports.
- platform-path-windows.spec.ts sends the Folder root identity local tree
  events require and the allowEditableTarget field local TrashKeyContext
  has.

(cherry picked from commit 127c5bb)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

Unexpected behavior when renaming or deleting a folder

2 participants