1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Update repo switch logic

We now always re-use the state of the repo if we're returning to it, and we always reset the windows to their default tabs.

We reset to default tabs because it's easy to implement. If people want to:
* have tab states be retained when switching
* have tab states specific to the current repo retained when switching back

Then we'll need to revisit this
This commit is contained in:
Jesse Duffield
2023-07-27 18:51:27 +10:00
parent 9c15ba0c0b
commit ae66f720f5
7 changed files with 49 additions and 33 deletions

View File

@ -276,7 +276,7 @@ func (self *GuiRepoState) GetSplitMainPanel() bool {
return self.SplitMainPanel
}
func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool, contextKey types.ContextKey) error {
func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.ContextKey) error {
var err error
gui.git, err = commands.NewGitCommand(
gui.Common,
@ -289,7 +289,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool, context
return err
}
contextToPush := gui.resetState(startArgs, reuseState)
contextToPush := gui.resetState(startArgs)
gui.resetHelpersAndControllers()
@ -324,26 +324,26 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool, context
// it gets a bit confusing to land back in the status panel when visiting a repo
// you've already switched from. There's no doubt some easy way to make the UX
// optimal for all cases but I'm too lazy to think about what that is right now
func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) types.Context {
func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
currentDir, err := os.Getwd()
if err != nil {
gui.c.Log.Error(err)
}
if reuseState {
if err == nil {
if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
gui.State = state
gui.State.ViewsSetup = false
if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
gui.State = state
gui.State.ViewsSetup = false
// setting this to nil so we don't get stuck based on a popup that was
// previously opened
gui.Mutexes.PopupMutex.Lock()
gui.State.CurrentPopupOpts = nil
gui.Mutexes.PopupMutex.Unlock()
contextTree := gui.State.Contexts
gui.State.WindowViewNameMap = initialWindowViewNameMap(contextTree)
return gui.c.CurrentContext()
}
} else {
gui.c.Log.Error(err)
}
// setting this to nil so we don't get stuck based on a popup that was
// previously opened
gui.Mutexes.PopupMutex.Lock()
gui.State.CurrentPopupOpts = nil
gui.Mutexes.PopupMutex.Unlock()
return gui.c.CurrentContext()
}
contextTree := gui.contextTree()
@ -351,6 +351,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) types.
initialScreenMode := initialScreenMode(startArgs, gui.Config)
gui.State = &GuiRepoState{
ViewsSetup: false,
Model: &types.Model{
CommitFiles: nil,
Files: make([]*models.File, 0),
@ -656,7 +657,7 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
}
// onNewRepo must be called after g.SetManager because SetManager deletes keybindings
if err := gui.onNewRepo(startArgs, false, context.NO_CONTEXT); err != nil {
if err := gui.onNewRepo(startArgs, context.NO_CONTEXT); err != nil {
return err
}