default editor fixes, fix bug with worktree panel not showing

This commit is contained in:
Cody Seibert
2025-12-16 12:35:36 -05:00
parent 9509c8ea00
commit d103d0aa45
6 changed files with 160 additions and 41 deletions

View File

@@ -101,6 +101,7 @@ export function WorktreeSelector({
const [isLoadingBranches, setIsLoadingBranches] = useState(false);
const [branchFilter, setBranchFilter] = useState("");
const [runningDevServers, setRunningDevServers] = useState<Map<string, DevServerInfo>>(new Map());
const [defaultEditorName, setDefaultEditorName] = useState<string>("Editor");
const currentWorktree = useAppStore((s) => s.getCurrentWorktree(projectPath));
const setCurrentWorktree = useAppStore((s) => s.setCurrentWorktree);
const setWorktreesInStore = useAppStore((s) => s.setWorktrees);
@@ -145,6 +146,21 @@ export function WorktreeSelector({
}
}, []);
const fetchDefaultEditor = useCallback(async () => {
try {
const api = getElectronAPI();
if (!api?.worktree?.getDefaultEditor) {
return;
}
const result = await api.worktree.getDefaultEditor();
if (result.success && result.result?.editorName) {
setDefaultEditorName(result.result.editorName);
}
} catch (error) {
console.error("Failed to fetch default editor:", error);
}
}, []);
const fetchBranches = useCallback(async (worktreePath: string) => {
setIsLoadingBranches(true);
try {
@@ -169,7 +185,8 @@ export function WorktreeSelector({
useEffect(() => {
fetchWorktrees();
fetchDevServers();
}, [fetchWorktrees, fetchDevServers]);
fetchDefaultEditor();
}, [fetchWorktrees, fetchDevServers, fetchDefaultEditor]);
// Refresh when refreshTrigger changes (but skip the initial render)
useEffect(() => {
@@ -442,10 +459,6 @@ export function WorktreeSelector({
? worktrees.find((w) => w.path === currentWorktree)
: worktrees.find((w) => w.isMain);
if (worktrees.length === 0 && !isLoading) {
// No git repo or loading
return null;
}
// Render a worktree tab with branch selector (for main) and actions dropdown
const renderWorktreeTab = (worktree: WorktreeInfo) => {
@@ -707,7 +720,7 @@ export function WorktreeSelector({
className="text-xs"
>
<ExternalLink className="w-3.5 h-3.5 mr-2" />
Open in Editor
Open in {defaultEditorName}
</DropdownMenuItem>
<DropdownMenuSeparator />
{/* Commit changes */}

View File

@@ -1222,7 +1222,19 @@ function createMockWorktreeAPI(): WorktreeAPI {
return {
success: true,
result: {
message: `Opened ${worktreePath} in editor`,
message: `Opened ${worktreePath} in VS Code`,
editorName: "VS Code",
},
};
},
getDefaultEditor: async () => {
console.log("[Mock] Getting default editor");
return {
success: true,
result: {
editorName: "VS Code",
editorCommand: "code",
},
};
},

View File

@@ -612,6 +612,8 @@ export class HttpApiClient implements ElectronAPI {
this.post("/api/worktree/switch-branch", { worktreePath, branchName }),
openInEditor: (worktreePath: string) =>
this.post("/api/worktree/open-in-editor", { worktreePath }),
getDefaultEditor: () =>
this.get("/api/worktree/default-editor"),
initGit: (projectPath: string) =>
this.post("/api/worktree/init-git", { projectPath }),
activate: (projectPath: string, worktreePath: string | null) =>

View File

@@ -796,6 +796,17 @@ export interface WorktreeAPI {
success: boolean;
result?: {
message: string;
editorName?: string;
};
error?: string;
}>;
// Get the default code editor name
getDefaultEditor: () => Promise<{
success: boolean;
result?: {
editorName: string;
editorCommand: string;
};
error?: string;
}>;