Skip to content

fix(explorer): handle Windows drive roots correctly in tree - #2938

Open
peter-lyr wants to merge 1 commit into
folke:mainfrom
peter-lyr:fix/windows-drive-root
Open

fix(explorer): handle Windows drive roots correctly in tree#2938
peter-lyr wants to merge 1 commit into
folke:mainfrom
peter-lyr:fix/windows-drive-root

Conversation

@peter-lyr

Copy link
Copy Markdown

Problem

On Windows, scandir("D:") (no trailing slash) resolves to the drive's current directory (e.g. D:/ob1) instead of the drive root D:/.

snacks' explorer tree.norm() stripped the trailing slash from "D:/" producing "D:". So opening or navigating to a drive root showed the current directory's contents (stale/obfuscated) instead of the actual root.

Repro: open explorer at D:/ob1, press <BS> (explorer_up) → it goes to D:/ but the list still shows ob1's children (Inbox, Life, ...) mislabeled as D:/... instead of the real root (79+ entries on the user's drive).

Fix

In lua/snacks/explorer/tree.lua:

  1. norm: keep the trailing slash for Windows drive roots (D:/), so scandir("D:/") resolves to the actual root.
  2. Tree:child: skip empty path segments produced by the trailing slash, and keep the trailing slash for drive-letter root nodes (D:/), while avoiding double slashes (D://name) when concatenating child paths.

Verified

Headless on Windows (nvim + real snacks):

  • open D:/ now shows the real drive root contents (many entries), not the stale current-dir list
  • opening D:/ob1 / D:/ob1/nvim unchanged
  • navigating from D:/ob1 up to D:/ now lists the drive root correctly
  • no double slashes in item paths

@github-actions github-actions Bot added explorer size/m Medium PR (<50 lines changed) labels Aug 24, 2026
On Windows, scandir("D:") (no trailing slash) resolves to the drive’s
current directory (e.g. D:/ob1) instead of the root D:/. snacks’ explorer
tree.norm() stripped the trailing slash from "D:/", producing "D:",
so opening or navigating to a drive root showed the current directory’s
contents (stale) instead of the actual root.

Fix two things in tree.lua:
1. norm: keep the trailing slash for Windows drive roots (D:/).
2. Tree:child: skip empty path segment produced by the trailing slash,
   and keep the trailing slash for drive-letter root nodes, avoiding
   double slashes (D://name) when joining child paths.

Verified headless on Windows:
- open D:/ -> real root listing (many entries), not stale ob1 contents
- normal directories unchanged
- navigating D:/ob1 up to D:/ now shows the drive root correctly
@peter-lyr
peter-lyr force-pushed the fix/windows-drive-root branch from 5c35ba6 to b12904e Compare August 24, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

explorer size/m Medium PR (<50 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant