fix: preserve Windows explorer reveal selection

This commit is contained in:
yangkun
2026-09-02 10:27:43 +08:00
parent c1992125d0
commit ac02598150
2 changed files with 8 additions and 6 deletions
+3 -4
View File
@@ -28,11 +28,10 @@ export function revealCommand(path: string, platform: NodeJS.Platform = process.
switch (platform) {
case 'darwin':
return { command: 'open', args: ['-R', path] }
// `explorer /select,<path>` — the classic "show in folder" incantation.
// Passed as separate argv entries (no shell); verify on Windows, with
// `cmd /c start "" explorer.exe "/select,<path>"` as the fallback.
// Explorer expects `/select,<path>` as one argument. Keep the spawn
// shell-free: a command shell would reinterpret valid path characters.
case 'win32':
return { command: 'explorer.exe', args: ['/select,', path] }
return { command: 'explorer.exe', args: [`/select,${path}`] }
default: {
const parent = parentOf(path)
return { command: 'xdg-open', args: [parent ?? path] }
+5 -2
View File
@@ -13,8 +13,11 @@ describe('revealCommand', () => {
expect(revealCommand('/a/b.txt', 'darwin')).toEqual({ command: 'open', args: ['-R', '/a/b.txt'] })
})
it('win32: `explorer /select,<path>` selects the file', () => {
expect(revealCommand('C:\\a\\b.txt', 'win32')).toEqual({ command: 'explorer.exe', args: ['/select,', 'C:\\a\\b.txt'] })
it('win32: passes /select,<path> as one shell-free Explorer argument', () => {
expect(revealCommand('C:\\work\\two words\\a.txt', 'win32')).toEqual({
command: 'explorer.exe',
args: ['/select,C:\\work\\two words\\a.txt'],
})
})
it('linux: `xdg-open` opens the containing directory (no common select protocol)', () => {