summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/editor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/utils/editor.ts')
-rw-r--r--packages/core/src/utils/editor.ts33
1 files changed, 22 insertions, 11 deletions
diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts
index 8d95a593..2d65d525 100644
--- a/packages/core/src/utils/editor.ts
+++ b/packages/core/src/utils/editor.ts
@@ -44,21 +44,28 @@ function commandExists(cmd: string): boolean {
}
}
-const editorCommands: Record<EditorType, { win32: string; default: string }> = {
- vscode: { win32: 'code.cmd', default: 'code' },
- vscodium: { win32: 'codium.cmd', default: 'codium' },
- windsurf: { win32: 'windsurf', default: 'windsurf' },
- cursor: { win32: 'cursor', default: 'cursor' },
- vim: { win32: 'vim', default: 'vim' },
- neovim: { win32: 'nvim', default: 'nvim' },
- zed: { win32: 'zed', default: 'zed' },
+/**
+ * Editor command configurations for different platforms.
+ * Each editor can have multiple possible command names, listed in order of preference.
+ */
+const editorCommands: Record<
+ EditorType,
+ { win32: string[]; default: string[] }
+> = {
+ vscode: { win32: ['code.cmd'], default: ['code'] },
+ vscodium: { win32: ['codium.cmd'], default: ['codium'] },
+ windsurf: { win32: ['windsurf'], default: ['windsurf'] },
+ cursor: { win32: ['cursor'], default: ['cursor'] },
+ vim: { win32: ['vim'], default: ['vim'] },
+ neovim: { win32: ['nvim'], default: ['nvim'] },
+ zed: { win32: ['zed'], default: ['zed', 'zeditor'] },
};
export function checkHasEditorType(editor: EditorType): boolean {
const commandConfig = editorCommands[editor];
- const command =
+ const commands =
process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
- return commandExists(command);
+ return commands.some((cmd) => commandExists(cmd));
}
export function allowEditorTypeInSandbox(editor: EditorType): boolean {
@@ -92,8 +99,12 @@ export function getDiffCommand(
return null;
}
const commandConfig = editorCommands[editor];
- const command =
+ const commands =
process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
+ const command =
+ commands.slice(0, -1).find((cmd) => commandExists(cmd)) ||
+ commands[commands.length - 1];
+
switch (editor) {
case 'vscode':
case 'vscodium':