From 37ca2a2395a84016fb779060cddfa51a36fecfce Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 31 May 2026 13:58:53 +0200 Subject: [PATCH] Press `e` in focused main view (when selection is showing) to edit that line --- pkg/gui/controllers/main_view_controller.go | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index 77b9b949f..4f837bd8d 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -32,12 +32,17 @@ func NewMainViewController( func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { // When a selection is shown, we surface the bindings that act on it - // (enter to dive into staging, escape to hide the selection). + // (enter to dive into staging, e to edit the selected line, escape to hide + // the selection). selectionShown := self.context.GetView().Highlight var enterDescription string + var editDescription string + var editTooltip string if selectionShown { enterDescription = self.c.Tr.EnterStaging + editDescription = self.c.Tr.EditFile + editTooltip = self.c.Tr.EditFileTooltip } return []*types.Binding{ @@ -66,6 +71,12 @@ func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*ty Description: enterDescription, DisplayOnScreen: selectionShown, }, + { + Keys: opts.GetKeys(opts.Config.Universal.Edit), + Handler: self.editLine, + Description: editDescription, + Tooltip: editTooltip, + }, { // overriding this because we want to read all of the task's output before we start searching Keys: opts.GetKeys(opts.Config.Universal.StartSearch), @@ -152,6 +163,20 @@ func (self *MainViewController) enter() error { return nil } +func (self *MainViewController) editLine() error { + if !self.context.GetView().Highlight { + return nil + } + // Figure out the clicked file and line the same way entering staging does. + path, lineNumber, ok := self.c.Helpers().Staging.GetFileAndLineForClickedDiffLine( + self.context.GetViewName(), self.context.GetView().SelectedLineIdx()) + if !ok { + return nil + } + lineNumber = self.c.Helpers().Diff.AdjustLineNumber(path, lineNumber, self.context.GetViewName()) + return self.c.Helpers().Files.EditFileAtLine(path, lineNumber) +} + func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error { if self.context.GetView().Highlight && !opts.IsDoubleClick { return nil