-
Notifications
You must be signed in to change notification settings - Fork 903
feat(desktop): add global default editor setting #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca36c2a
1ee467d
f3c5197
6587ce7
2de8344
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -100,7 +100,7 @@ const ALL_APP_OPTIONS = [ | |||||||||||||||||
| ]; | ||||||||||||||||||
|
|
||||||||||||||||||
| export const getAppOption = (id: ExternalApp) => | ||||||||||||||||||
| ALL_APP_OPTIONS.find((app) => app.id === id) ?? APP_OPTIONS[1]; | ||||||||||||||||||
| ALL_APP_OPTIONS.find((app) => app.id === id); | ||||||||||||||||||
|
|
||||||||||||||||||
| export interface OpenInButtonProps { | ||||||||||||||||||
| path: string | undefined; | ||||||||||||||||||
|
|
@@ -126,11 +126,10 @@ export function OpenInButton({ | |||||||||||||||||
| const showCopyPathShortcut = | ||||||||||||||||||
| showShortcuts && copyPathShortcut !== "Unassigned"; | ||||||||||||||||||
|
|
||||||||||||||||||
| const { data: defaultApp = "cursor" } = | ||||||||||||||||||
| electronTrpc.projects.getDefaultApp.useQuery( | ||||||||||||||||||
| { projectId: projectId as string }, | ||||||||||||||||||
| { enabled: !!projectId }, | ||||||||||||||||||
| ); | ||||||||||||||||||
| const { data: defaultApp } = electronTrpc.projects.getDefaultApp.useQuery( | ||||||||||||||||||
| { projectId: projectId as string }, | ||||||||||||||||||
| { enabled: !!projectId }, | ||||||||||||||||||
| ); | ||||||||||||||||||
|
Comment on lines
+129
to
+132
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n apps/desktop/src/renderer/components/OpenInButton/OpenInButton.tsxRepository: superset-sh/superset Length of output: 12118 🏁 Script executed: rg -n "OpenInButton" --type=tsx --type=ts -B 2 -A 5Repository: superset-sh/superset Length of output: 91 🏁 Script executed: rg -n "OpenInButton" -B 2 -A 5Repository: superset-sh/superset Length of output: 6954 🏁 Script executed: cat -n apps/desktop/src/renderer/components/ConfigFilePreview/ConfigFilePreview.tsx | grep -A 10 -B 5 "OpenInButton"Repository: superset-sh/superset Length of output: 1277 🏁 Script executed: cat -n apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/TopBar/components/OpenInMenuButton/OpenInMenuButton.tsx | head -80Repository: superset-sh/superset Length of output: 3371 🏁 Script executed: cat -n apps/desktop/src/renderer/routes/_authenticated/settings/components/ClickablePath/ClickablePath.tsx | head -80Repository: superset-sh/superset Length of output: 3199 🏁 Script executed: rg "<OpenInButton" -B 3 -A 5Repository: superset-sh/superset Length of output: 1034 🏁 Script executed: rg "OpenInButton" --type ts --type tsx | grep -v "import\|export\|interface\|from\|props\|Props"Repository: superset-sh/superset Length of output: 91 🏁 Script executed: cat -n apps/desktop/src/renderer/components/ConfigFilePreview/ConfigFilePreview.tsx | head -20Repository: superset-sh/superset Length of output: 762
The idiomatic pattern for enabled-guarded tRPC queries is the non-null assertion Proposed fix- const { data: defaultApp } = electronTrpc.projects.getDefaultApp.useQuery(
- { projectId: projectId as string },
+ const { data: defaultApp } = electronTrpc.projects.getDefaultApp.useQuery(
+ { projectId: projectId! },Note: While 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| const openInApp = electronTrpc.external.openInApp.useMutation({ | ||||||||||||||||||
| onSuccess: () => { | ||||||||||||||||||
|
|
@@ -141,7 +140,7 @@ export function OpenInButton({ | |||||||||||||||||
| }); | ||||||||||||||||||
| const copyPath = electronTrpc.external.copyPath.useMutation(); | ||||||||||||||||||
|
|
||||||||||||||||||
| const currentApp = getAppOption(defaultApp); | ||||||||||||||||||
| const currentApp = defaultApp ? (getAppOption(defaultApp) ?? null) : null; | ||||||||||||||||||
|
|
||||||||||||||||||
| const handleOpenIn = (app: ExternalApp) => { | ||||||||||||||||||
| if (!path) return; | ||||||||||||||||||
|
|
@@ -156,13 +155,13 @@ export function OpenInButton({ | |||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const handleOpenLastUsed = () => { | ||||||||||||||||||
| if (!path) return; | ||||||||||||||||||
| if (!path || !defaultApp) return; | ||||||||||||||||||
| openInApp.mutate({ path, app: defaultApp, projectId }); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <ButtonGroup> | ||||||||||||||||||
| {label && ( | ||||||||||||||||||
| {label && currentApp && ( | ||||||||||||||||||
| <Tooltip> | ||||||||||||||||||
| <TooltipTrigger asChild> | ||||||||||||||||||
| <Button | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolveDefaultEditorcan return a non-editor app fromproject.defaultApp.The global default (
settings.defaultEditor) is properly guarded against non-editor apps by bothensureGlobalDefaultEditorandsetDefaultEditor. However,project.defaultAppstores whatever app was last used (including Finder, Terminal, etc.), andresolveDefaultEditorreturns it without filtering.If a user's last action on a project was "Open in Finder", then
openFileInEditorwould resolve to"finder"and callshell.showItemInFolderinstead of launching an editor.Consider filtering out non-editor apps from the project-level lookup:
Proposed fix
export function resolveDefaultEditor(projectId?: string): ExternalApp | null { if (projectId) { const project = localDb .select() .from(projects) .where(eq(projects.id, projectId)) .get(); - if (project?.defaultApp) return project.defaultApp; + if (project?.defaultApp && !nonEditorSet.has(project.defaultApp)) + return project.defaultApp; } const row = localDb.select().from(settings).get(); return row?.defaultEditor ?? null; }🤖 Prompt for AI Agents