fix integration test

This commit is contained in:
Jesse Duffield 2022-01-18 20:43:08 +11:00
parent dbb8b17d83
commit b6fb7f1365
4 changed files with 41 additions and 6 deletions

View file

@ -136,7 +136,7 @@ func (gui *Gui) contextTree() ContextTree {
Key: MAIN_NORMAL_CONTEXT_KEY, Key: MAIN_NORMAL_CONTEXT_KEY,
}, },
Staging: &BasicContext{ Staging: &BasicContext{
OnRenderToMain: func(opts ...OnFocusOpts) error { OnFocus: func(opts ...OnFocusOpts) error {
forceSecondaryFocused := false forceSecondaryFocused := false
selectedLineIdx := -1 selectedLineIdx := -1
if len(opts) > 0 && opts[0].ClickedViewName != "" { if len(opts) > 0 && opts[0].ClickedViewName != "" {
@ -147,20 +147,20 @@ func (gui *Gui) contextTree() ContextTree {
forceSecondaryFocused = true forceSecondaryFocused = true
} }
} }
return gui.handleRefreshStagingPanel(forceSecondaryFocused, selectedLineIdx) return gui.onStagingFocus(forceSecondaryFocused, selectedLineIdx)
}, },
Kind: MAIN_CONTEXT, Kind: MAIN_CONTEXT,
ViewName: "main", ViewName: "main",
Key: MAIN_STAGING_CONTEXT_KEY, Key: MAIN_STAGING_CONTEXT_KEY,
}, },
PatchBuilding: &BasicContext{ PatchBuilding: &BasicContext{
OnRenderToMain: func(opts ...OnFocusOpts) error { OnFocus: func(opts ...OnFocusOpts) error {
selectedLineIdx := -1 selectedLineIdx := -1
if len(opts) > 0 && (opts[0].ClickedViewName == "main" || opts[0].ClickedViewName == "secondary") { if len(opts) > 0 && (opts[0].ClickedViewName == "main" || opts[0].ClickedViewName == "secondary") {
selectedLineIdx = opts[0].ClickedViewLineIdx selectedLineIdx = opts[0].ClickedViewLineIdx
} }
return gui.handleRefreshPatchBuildingPanel(selectedLineIdx) return gui.onPatchBuildingFocus(selectedLineIdx)
}, },
Kind: MAIN_CONTEXT, Kind: MAIN_CONTEXT,
ViewName: "main", ViewName: "main",

View file

@ -32,7 +32,7 @@ func (gui *Gui) IncreaseContextInDiffView() error {
} }
gui.UserConfig.Git.DiffContextSize = gui.UserConfig.Git.DiffContextSize + 1 gui.UserConfig.Git.DiffContextSize = gui.UserConfig.Git.DiffContextSize + 1
return gui.currentStaticContext().HandleRenderToMain() return gui.handleDiffContextSizeChange()
} }
return nil return nil
@ -47,12 +47,25 @@ func (gui *Gui) DecreaseContextInDiffView() error {
} }
gui.UserConfig.Git.DiffContextSize = old_size - 1 gui.UserConfig.Git.DiffContextSize = old_size - 1
return gui.currentStaticContext().HandleRenderToMain() return gui.handleDiffContextSizeChange()
} }
return nil return nil
} }
func (gui *Gui) handleDiffContextSizeChange() error {
currentContext := gui.currentStaticContext()
switch currentContext.GetKey() {
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
case MAIN_PATCH_BUILDING_CONTEXT_KEY:
return gui.handleRefreshPatchBuildingPanel(-1)
case MAIN_STAGING_CONTEXT_KEY:
return gui.handleRefreshStagingPanel(false, -1)
default:
return currentContext.HandleRenderToMain()
}
}
func (gui *Gui) CheckCanChangeContext() error { func (gui *Gui) CheckCanChangeContext() error {
if gui.Git.Patch.PatchManager.Active() { if gui.Git.Patch.PatchManager.Active() {
return errors.New(gui.Tr.CantChangeContextSizeError) return errors.New(gui.Tr.CantChangeContextSizeError)

View file

@ -62,6 +62,17 @@ func (gui *Gui) handleRefreshPatchBuildingPanel(selectedLineIdx int) error {
return gui.refreshPatchBuildingPanel(selectedLineIdx) return gui.refreshPatchBuildingPanel(selectedLineIdx)
} }
func (gui *Gui) onPatchBuildingFocus(selectedLineIdx int) error {
gui.Mutexes.LineByLinePanelMutex.Lock()
defer gui.Mutexes.LineByLinePanelMutex.Unlock()
if gui.State.Panels.LineByLine == nil || selectedLineIdx != -1 {
return gui.refreshPatchBuildingPanel(selectedLineIdx)
}
return nil
}
func (gui *Gui) handleToggleSelectionForPatch() error { func (gui *Gui) handleToggleSelectionForPatch() error {
err := gui.withLBLActiveCheck(func(state *LblPanelState) error { err := gui.withLBLActiveCheck(func(state *LblPanelState) error {
toggleFunc := gui.Git.Patch.PatchManager.AddFileLineRange toggleFunc := gui.Git.Patch.PatchManager.AddFileLineRange

View file

@ -74,6 +74,17 @@ func (gui *Gui) handleRefreshStagingPanel(forceSecondaryFocused bool, selectedLi
return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx) return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx)
} }
func (gui *Gui) onStagingFocus(forceSecondaryFocused bool, selectedLineIdx int) error {
gui.Mutexes.LineByLinePanelMutex.Lock()
defer gui.Mutexes.LineByLinePanelMutex.Unlock()
if gui.State.Panels.LineByLine == nil || selectedLineIdx != -1 {
return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx)
}
return nil
}
func (gui *Gui) handleTogglePanel() error { func (gui *Gui) handleTogglePanel() error {
return gui.withLBLActiveCheck(func(state *LblPanelState) error { return gui.withLBLActiveCheck(func(state *LblPanelState) error {
state.SecondaryFocused = !state.SecondaryFocused state.SecondaryFocused = !state.SecondaryFocused