diff options
Diffstat (limited to 'packages/core/src/utils/editor.ts')
| -rw-r--r-- | packages/core/src/utils/editor.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts index 4d09e3a9..15c970d0 100644 --- a/packages/core/src/utils/editor.ts +++ b/packages/core/src/utils/editor.ts @@ -8,6 +8,10 @@ import { execSync, spawn } from 'child_process'; export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim'; +function isValidEditorType(editor: string): editor is EditorType { + return ['vscode', 'windsurf', 'cursor', 'vim'].includes(editor); +} + interface DiffCommand { command: string; args: string[]; @@ -32,13 +36,35 @@ const editorCommands: Record<EditorType, { win32: string; default: string }> = { vim: { win32: 'vim', default: 'vim' }, }; -export function checkHasEditor(editor: EditorType): boolean { +export function checkHasEditorType(editor: EditorType): boolean { const commandConfig = editorCommands[editor]; const command = process.platform === 'win32' ? commandConfig.win32 : commandConfig.default; return commandExists(command); } +export function allowEditorTypeInSandbox(editor: EditorType): boolean { + const notUsingSandbox = !process.env.SANDBOX; + if (['vscode', 'windsurf', 'cursor'].includes(editor)) { + return notUsingSandbox; + } + return true; +} + +/** + * Check if the editor is valid and can be used. + * Returns false if preferred editor is not set / invalid / not available / not allowed in sandbox. + */ +export function isEditorAvailable(editor: string | undefined): boolean { + if (editor && isValidEditorType(editor)) { + return ( + checkHasEditorType(editor as EditorType) && + allowEditorTypeInSandbox(editor as EditorType) + ); + } + return false; +} + /** * Get the diff command for a specific editor. */ |
