fix: preserve Windows explorer reveal selection
This commit is contained in:
@@ -28,11 +28,10 @@ export function revealCommand(path: string, platform: NodeJS.Platform = process.
|
|||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return { command: 'open', args: ['-R', path] }
|
return { command: 'open', args: ['-R', path] }
|
||||||
// `explorer /select,<path>` — the classic "show in folder" incantation.
|
// Explorer expects `/select,<path>` as one argument. Keep the spawn
|
||||||
// Passed as separate argv entries (no shell); verify on Windows, with
|
// shell-free: a command shell would reinterpret valid path characters.
|
||||||
// `cmd /c start "" explorer.exe "/select,<path>"` as the fallback.
|
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return { command: 'explorer.exe', args: ['/select,', path] }
|
return { command: 'explorer.exe', args: [`/select,${path}`] }
|
||||||
default: {
|
default: {
|
||||||
const parent = parentOf(path)
|
const parent = parentOf(path)
|
||||||
return { command: 'xdg-open', args: [parent ?? path] }
|
return { command: 'xdg-open', args: [parent ?? path] }
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ describe('revealCommand', () => {
|
|||||||
expect(revealCommand('/a/b.txt', 'darwin')).toEqual({ command: 'open', args: ['-R', '/a/b.txt'] })
|
expect(revealCommand('/a/b.txt', 'darwin')).toEqual({ command: 'open', args: ['-R', '/a/b.txt'] })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('win32: `explorer /select,<path>` selects the file', () => {
|
it('win32: passes /select,<path> as one shell-free Explorer argument', () => {
|
||||||
expect(revealCommand('C:\\a\\b.txt', 'win32')).toEqual({ command: 'explorer.exe', args: ['/select,', 'C:\\a\\b.txt'] })
|
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)', () => {
|
it('linux: `xdg-open` opens the containing directory (no common select protocol)', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user