From d80802c1f9ae7cb64bc8bcc571c60799d0758771 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 20 Jun 2026 16:07:05 +0200 Subject: [PATCH] Keep hunk mode when clicking another hunk in the focused main view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once in hunk mode, clicking another change line reset the selection to a single line, so you had to press `a` again for each block you wanted to stage (a behaviour the main view inherited from the staging and patch- building panels). Preserve hunk mode across clicks instead: a click on a change line re-selects that whole block, while a click on context — or any click when we weren't in hunk mode — drops to a single line, where the click points precisely (e.g. to edit it). The two click handlers shared an identical selection body, so unify them into one helper and make the change in a single place. Co-Authored-By: Claude Opus 4.8 (1M context) --- pkg/gui/controllers/main_view_controller.go | 31 ++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index d5679049e..0b580b985 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -969,17 +969,7 @@ func githubPullRequestLineURL(prURL string, commitSha string, relativePath strin } func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error { - if !self.isDiffView() { - return nil - } - // A click points at a line, so it sets a single-line selection there; a - // double-click additionally dives into staging/patch-building for that line. - resetDiffSelectMode(self.context) - showSelectionAtLine(self.context.GetView(), opts.Y, false) - if opts.IsDoubleClick { - return self.enterForLine(opts.Y) - } - return nil + return self.selectClickedDiffLine(opts) } func (self *MainViewController) editClickedLine(opts gocui.ViewMouseBindingOpts) error { @@ -988,11 +978,26 @@ func (self *MainViewController) editClickedLine(opts gocui.ViewMouseBindingOpts) func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error { self.c.Context().Push(self.context, types.OnFocusOpts{}) + return self.selectClickedDiffLine(opts) +} + +// selectClickedDiffLine sets the focused main view's selection from a click at view +// line opts.Y. In hunk mode a click on a change line keeps hunk mode and selects that +// whole block, so clicking from hunk to hunk stays ready to stage; a click on context +// drops to a single line, as does any click when we weren't in hunk mode — the click +// points at the line precisely (e.g. to edit it). A double-click additionally dives +// into staging/patch-building for that line. +func (self *MainViewController) selectClickedDiffLine(opts gocui.ViewMouseBindingOpts) error { if !self.isDiffView() { return nil } - resetDiffSelectMode(self.context) - showSelectionAtLine(self.context.GetView(), opts.Y, false) + view := self.context.GetView() + if self.sel().Mode == context.DiffSelectModeHunk && self.c.Helpers().Staging.IsChangeLine(view, opts.Y) { + self.selectHunkAround(opts.Y) + } else { + resetDiffSelectMode(self.context) + showSelectionAtLine(view, opts.Y, false) + } if opts.IsDoubleClick { return self.enterForLine(opts.Y) }