diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-30 23:24:24 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:52 +1000 |
commit | 8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch) | |
tree | 0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui/controllers/helpers/patch_building_helper.go | |
parent | 826128a8e03fb50f7287029ebac93c85712faecb (diff) |
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the
gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui/controllers/helpers/patch_building_helper.go')
-rw-r--r-- | pkg/gui/controllers/helpers/patch_building_helper.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index 59de50b99..b58812733 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -4,6 +4,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -60,3 +61,59 @@ func (self *PatchBuildingHelper) Reset() error { // refreshing the current context so that the secondary panel is hidden if necessary. return self.c.PostRefreshUpdate(self.c.CurrentContext()) } + +func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpts) error { + selectedLineIdx := -1 + if opts.ClickedWindowName == "main" { + selectedLineIdx = opts.ClickedViewLineIdx + } + + if !self.git.Patch.PatchBuilder.Active() { + return self.Escape() + } + + // get diff from commit file that's currently selected + path := self.contexts.CommitFiles.GetSelectedPath() + if path == "" { + return nil + } + + ref := self.contexts.CommitFiles.CommitFileTreeViewModel.GetRef() + to := ref.RefName() + from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) + diff, err := self.git.WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView()) + if err != nil { + return err + } + + secondaryDiff := self.git.Patch.PatchBuilder.RenderPatchForFile(path, false, false) + if err != nil { + return err + } + + context := self.contexts.CustomPatchBuilder + + oldState := context.GetState() + + state := patch_exploring.NewState(diff, selectedLineIdx, oldState, self.c.Log) + context.SetState(state) + if state == nil { + return self.Escape() + } + + mainContent := context.GetContentToRender(true) + + self.contexts.CustomPatchBuilder.FocusSelection() + + return self.c.RenderToMainViews(types.RefreshMainOpts{ + Pair: self.c.MainViewPairs().PatchBuilding, + Main: &types.ViewUpdateOpts{ + Task: types.NewRenderStringWithoutScrollTask(mainContent), + Title: self.c.Tr.Patch, + }, + Secondary: &types.ViewUpdateOpts{ + Task: types.NewRenderStringWithoutScrollTask(secondaryDiff), + Title: self.c.Tr.CustomPatch, + }, + }) +} |