Add open-in-editor feature with Cmd+O shortcut #2
Mergedjuliusmarmingemerged 5 commits into
main fromjuliusmarminge/open-in-editormerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub- apps/desktop/src/main.ts lines 148 to 148Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -125,3 +132,21 @@125132 }),126133 );127134135+ // Shell handlers136+ ipcMain.handle(137+ IPC_CHANNELS.shellOpenInEditor,138+ async (_event, cwd: string, editor: string) => {139+ if (editor === "file-manager") {140+ await shell.openPath(cwd);141+ return;142+ }143+ const EDITOR_COMMANDS: Record<string, { command: string; args: (cwd: string) => string[] }> = {144+ cursor: { command: "cursor", args: (p) => [p] },145+ };146+ const entry = EDITOR_COMMANDS[editor];147+ if (!entry) throw new Error(`Unknown editor: ${editor}`);148+ const child = spawn(entry.command, entry.args(cwd), {149+ detached: true,150+ stdio: "ignore",151+ });152+ child.unref();
- @@ -126,2 +133,21 @@126133 );127134135+ // Shell handlers136+ ipcMain.handle(137+ IPC_CHANNELS.shellOpenInEditor,138+ async (_event, cwd: string, editor: string) => {139+ if (editor === "file-manager") {140+ await shell.openPath(cwd);141+ return;142+ }143+ const EDITOR_COMMANDS: Record<string, { command: string; args: (cwd: string) => string[] }> = {144+ cursor: { command: "cursor", args: (p) => [p] },145+ };146+ const entry = EDITOR_COMMANDS[editor];147+ if (!entry) throw new Error(`Unknown editor: ${editor}`);148+ const child = spawn(entry.command, entry.args(cwd), {149+ detached: true,150+ stdio: "ignore",151+ });152+ child.unref();153+ },apps/desktop/src/main.ts lines 143 to 145OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -125,3 +132,14 @@125132 }),126133 );127134135+ // Shell handlers136+ ipcMain.handle(137+ IPC_CHANNELS.shellOpenInEditor,138+ async (_event, cwd: string, editor: string) => {139+ if (editor === "file-manager") {140+ await shell.openPath(cwd);141+ return;142+ }143+ const EDITOR_COMMANDS: Record<string, { command: string; args: (cwd: string) => string[] }> = {144+ cursor: { command: "cursor", args: (p) => [p] },145+ };@@ -51,3 +63,7 @@5163 const [isSending, setIsSending] = useState(false);5264 const [isConnecting, setIsConnecting] = useState(false);5365 const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);66+ const [isEditorMenuOpen, setIsEditorMenuOpen] = useState(false);67+ const [lastEditor, setLastEditor] = useState(68+ () => localStorage.getItem(LAST_EDITOR_KEY) ?? EDITORS[0].id,69+ );apps/renderer/src/components/ChatView.tsx lines 222 to 230Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -146,0 +171,21 @@171+ !editorMenuRef.current.contains(event.target)172+ ) {173+ setIsEditorMenuOpen(false);174+ }175+ };176+177+ window.addEventListener("mousedown", handleClickOutside);178+ return () => {179+ window.removeEventListener("mousedown", handleClickOutside);180+ };181+ }, [isEditorMenuOpen]);182+183+ // Cmd+O / Ctrl+O to open in last-used editor184+ useEffect(() => {185+ const handler = (e: globalThis.KeyboardEvent) => {186+ if (e.key === "o" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {187+ e.preventDefault();188+ if (api && activeProject) {189+ void api.shell.openInEditor(activeProject.cwd, lastEditor);190+ }191+ }
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Walkthrough#
Adds an "open in editor" feature: new
EDITORSandEditorIdtypes,IPC_CHANNELS.shellOpenInEditorplus main-process handler,nativeApi.shell.openInEditorin preload, and renderer UI/shortcut to invoke and persist the chosen editor.Changes#
apps/desktop/src/main.tsshellandEDITORS; registersIPC_CHANNELS.shellOpenInEditorhandler that looks up editor by id, throws on unknown, usesshell.openPath(cwd)for file-manager orspawn(detached, stdio ignored) andunref()for editor commands.apps/desktop/src/preload.tsnativeApi.shell.openInEditor(cwd: string, editor: EditorId)which invokesIPC_CHANNELS.shellOpenInEditorviaipcRenderer.invoke.apps/renderer/src/components/ChatView.tsxisEditorMenuOpenandlastEditorstate withlocalStoragepersistence, outside-click handling, Cmd/Ctrl+O shortcut to open last editor, and callsapi.shell.openInEditor.packages/contracts/src/ipc.tsEDITORSarray andEditorIdtype, addsIPC_CHANNELS.shellOpenInEditor, and extendsNativeApiwithshell.openInEditor(cwd: string, editor: EditorId): Promise<void>.manifest_file,package.jsonSequence Diagram#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉
🧹 Recent nitpick comments
Comment `@coderabbitai help` to get the list of available commands and usage tips.