WIP After going straight to patch building from main view, esc goes all the way back out

I *think* I like it better this way, but it needs more testing.
This commit is contained in:
Stefan Haller 2025-03-29 16:52:55 +01:00
parent 63ffb829c0
commit 89b67cf938
4 changed files with 36 additions and 6 deletions

View file

@ -519,7 +519,7 @@ func (self *CommitFilesController) toggleAllForPatch(_ *filetree.CommitFileNode)
}
func (self *CommitFilesController) enter(node *filetree.CommitFileNode) error {
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "", ClickedViewLineIdx: -1, ClickedViewRealLineIdx: -1})
return self.c.Helpers().CommitFiles.EnterCommitFile(node, nil, types.OnFocusOpts{ClickedWindowName: "", ClickedViewLineIdx: -1, ClickedViewRealLineIdx: -1})
}
// NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics
@ -576,7 +576,9 @@ func (self *CommitFilesController) GetOnClickFocusedMainView() func(mainViewName
}
}
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
// Entered from the commit files panel's own focused main view, so escape
// should just pop back to it; no special escape context needed.
return self.c.Helpers().CommitFiles.EnterCommitFile(node, nil, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
}
}

View file

@ -21,7 +21,11 @@ func NewCommitFilesHelper(c *HelperCommon, patchBuildingHelper *PatchBuildingHel
}
}
func (self *CommitFilesHelper) EnterCommitFile(node *filetree.CommitFileNode, opts types.OnFocusOpts) error {
// escapeContext is the side panel that escaping the patch builder should return
// to, for the case where we're entering it straight from a focused main view;
// it's nil for the normal flow that goes through the commit files panel. See
// PatchBuildingHelper.escapeContext.
func (self *CommitFilesHelper) EnterCommitFile(node *filetree.CommitFileNode, escapeContext types.Context, opts types.OnFocusOpts) error {
if node.File == nil {
self.handleToggleCommitFileDirCollapsed(node)
return nil
@ -48,6 +52,11 @@ func (self *CommitFilesHelper) EnterCommitFile(node *filetree.CommitFileNode, op
}
}
// Set on every entry (so it can't leak from a previous main-view
// entry into a subsequent normal one), right as we push the patch
// builder.
self.patchBuildingHelper.escapeContext = escapeContext
self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts)
self.patchBuildingHelper.ShowHunkStagingHint()

View file

@ -10,6 +10,14 @@ import (
type PatchBuildingHelper struct {
c *HelperCommon
// When patch building is entered straight from a focused main view (rather
// than from the commit files panel), this records the side panel to return
// to on escape, so that we skip the commit files panel we never really
// visited. It is nil for the normal flow, where escape just pops back to the
// commit files panel. Set on every entry into patch building (see
// CommitFilesHelper.EnterCommitFile) so it can't leak between flows.
escapeContext types.Context
}
func NewPatchBuildingHelper(
@ -32,9 +40,17 @@ func (self *PatchBuildingHelper) ShowHunkStagingHint() {
}
}
// takes us from the patch building panel back to the commit files panel
// takes us from the patch building panel back to the commit files panel, or
// straight back to the side panel if we entered patch building from a focused
// main view (see escapeContext)
func (self *PatchBuildingHelper) Escape() {
self.c.Context().Pop()
if self.escapeContext != nil {
escapeContext := self.escapeContext
self.escapeContext = nil
self.c.Context().Push(escapeContext, types.OnFocusOpts{})
} else {
self.c.Context().Pop()
}
}
// kills the custom patch and returns us back to the commit files panel if needed

View file

@ -83,7 +83,10 @@ func (self *SwitchToDiffFilesController) GetOnClickFocusedMainView() func(mainVi
context.GetViewTrait().FocusPoint(
context.ModelIndexToViewIndex(idx), false)
node = context.GetSelected()
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
// We entered patch building straight from the focused main view, so
// escaping it should take us all the way back out to this side panel,
// skipping the commit files panel we never really visited.
return self.c.Helpers().CommitFiles.EnterCommitFile(node, self.context, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
}
}