Force Cursor folder opens into new windows (#2204)

This commit is contained in:
Jinjing
2026-05-17 20:05:57 -07:00
committed by GitHub
parent 193907cc69
commit 4634ffb4d3
2 changed files with 37 additions and 2 deletions
+18
View File
@@ -251,6 +251,24 @@ describe('registerShellHandlers', () => {
])
})
it('forces Cursor launcher folders into a new window', async () => {
resolveCliCommandMock.mockReturnValueOnce('/usr/local/bin/cursor')
const workspacePath = resolve('workspace')
const handler = getHandler('shell:openInExternalEditor')
await expect(handler({}, workspacePath, 'cursor')).resolves.toEqual({ ok: true })
expect(getSpawnArgsForWindowsMock).toHaveBeenCalledWith('/usr/local/bin/cursor', [
'--new-window',
normalize(workspacePath)
])
resolveCliCommandMock.mockReturnValueOnce('C:\\Cursor\\cursor.cmd')
await expect(handler({}, workspacePath, 'cursor')).resolves.toEqual({ ok: true })
expect(getSpawnArgsForWindowsMock).toHaveBeenLastCalledWith('C:\\Cursor\\cursor.cmd', [
'--new-window',
normalize(workspacePath)
])
})
it('falls back to VS Code when command is blank', async () => {
const workspacePath = resolve('workspace')
const handler = getHandler('shell:openInExternalEditor')
+19 -2
View File
@@ -1,7 +1,7 @@
import { ipcMain, shell, dialog } from 'electron'
import { spawn } from 'node:child_process'
import { constants, copyFile, stat } from 'node:fs/promises'
import { isAbsolute, normalize } from 'node:path'
import { basename, isAbsolute, normalize, win32 } from 'node:path'
import { fileURLToPath } from 'node:url'
import type { ShellOpenLocalPathResult } from '../../shared/shell-open-types'
import { resolveCliCommand } from '../codex-cli/command'
@@ -51,9 +51,26 @@ function resolveExternalEditorCommand(command?: string): string {
return resolveCliCommand(trimmed || EXTERNAL_EDITOR_CLI_COMMAND)
}
function getLauncherBaseName(command: string): string {
const name = command.includes('\\') ? win32.basename(command) : basename(command)
return name.replace(/\.(?:cmd|exe|bat)$/i, '').toLowerCase()
}
function buildExternalEditorArgs(editorCommand: string, pathValue: string): string[] {
if (getLauncherBaseName(editorCommand) === 'cursor') {
// Why: Cursor can route bare folder launches through the last active
// workbench. A new window keeps "Open in Cursor" scoped to this worktree.
return ['--new-window', pathValue]
}
return [pathValue]
}
async function launchExternalEditor(pathValue: string, command?: string): Promise<void> {
const editorCommand = resolveExternalEditorCommand(command)
const { spawnCmd, spawnArgs } = getSpawnArgsForWindows(editorCommand, [pathValue])
const { spawnCmd, spawnArgs } = getSpawnArgsForWindows(
editorCommand,
buildExternalEditorArgs(editorCommand, pathValue)
)
await new Promise<void>((resolvePromise, rejectPromise) => {
const child = spawn(spawnCmd, spawnArgs, {