feat: External editor settings (#882)

This commit is contained in:
Leo
2025-06-12 02:21:54 +01:00
committed by GitHub
parent dd53e5c96a
commit 1ef68e0612
23 changed files with 849 additions and 81 deletions

View File

@@ -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.
*/