feat(ui): open file in editor with e shortcut#310
Conversation
Greptile SummaryAdds an
Confidence Score: 4/5Safe to merge — the feature is well-isolated, the TUI suspend/resume lifecycle is handled correctly, and the error-notice path is clean. The core logic in openInEditor.ts has two minor gaps: the +line flag only works with vim-family editors (VS Code users will see unexpected behavior), and the editor process exit code is not inspected, so a crashed or errored editor still triggers a diff refresh. Neither blocks correct operation for the majority of users. src/ui/lib/openInEditor.ts — the +line flag assumption and missing exit-code check. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant KeyboardShortcut as useAppKeyboardShortcuts
participant App as App.tsx
participant OpenEditor as openInEditor.ts
participant Renderer as CliRenderer
participant Editor as $EDITOR (shell)
participant Diff as refreshCurrentInput
User->>KeyboardShortcut: press 'e'
KeyboardShortcut->>App: triggerEditSelectedFile()
App->>OpenEditor: "openSelectedFileInEditor({ file, renderer, selectedHunk })"
alt no file selected / no $EDITOR / file missing on disk
OpenEditor-->>App: error message string
App->>App: showSessionNotice(message)
else file exists and $EDITOR set
OpenEditor->>Renderer: suspend()
OpenEditor->>Editor: "spawnSync(command, { shell: true, stdio: inherit })"
Editor-->>OpenEditor: result (status, error)
OpenEditor->>Renderer: resume()
OpenEditor-->>App: null (success)
App->>Diff: triggerRefreshCurrentInput()
end
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/ui/lib/openInEditor.ts:47
**`+line` flag not supported by VS Code and other common editors**
The `+${line}` flag is a vi/vim convention. Editors like VS Code (`code`) don't support it — VS Code will try to open a file literally named `+1` alongside the real file, which creates a confusing error or spuriously creates an untitled document. Similarly, `subl` (Sublime Text), `kate`, and others use different mechanisms for jump-to-line. For users with `EDITOR=code` or `EDITOR=subl`, line positioning silently breaks.
### Issue 2 of 2
src/ui/lib/openInEditor.ts:58-62
**`result.status` exit code is not checked**
`spawnSync` sets `result.error` only for Node.js-level spawn failures (e.g. `ENOENT`). If the editor itself exits with a non-zero status (permission error, crash, etc.), `result.error` is `undefined` and the function returns `null`, silently triggering a diff refresh as if editing succeeded. Checking `result.status` closes this gap.
```suggestion
if (result.error) {
return `Failed to launch editor: ${result.error.message}`;
}
if (result.status !== 0 && result.status !== null) {
return `Editor exited with status ${result.status}.`;
}
return null;
```
Reviews (1): Last reviewed commit: "feat(ui): open file in editor with e sho..." | Re-trigger Greptile |
26cabc7 to
f60283f
Compare
|
@benvinegar - should be ready - lmk if anything you don't like. |
|
@duarteocarmo This is pretty handy. I just played with it. But I notice there's a flash of content when you hit |
|
@benvinegar - for what editor? terminal based or? |
f60283f to
9d8f245
Compare
|
@benvinegar - ok. I made a slight change.
lmk what you think |
|
Could you add tests for src/ui/lib/openInEditor.ts? Also a Windows concern: it builds a shell command with Unix-style quoting + shell: true, which might not work w/ cmd.exe. And please add a changelog entry. |
Summary
eshortcut to open the currently selected sidebar file in$EDITORI also ran the tests - and they passed.