diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-03 15:56:11 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 19:34:32 +1000 |
commit | 0898a7bb57bc399ff016cea06a0ca35d0bf54d6b (patch) | |
tree | bc1a26ea01d493f4661bf8352cf0f1744dbf33ff /pkg/gui | |
parent | fafd5234bd7be6916e00712a3a138bf2ee92e99b (diff) |
refactor
Diffstat (limited to 'pkg/gui')
31 files changed, 189 insertions, 165 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 956b67e96..4d0c69a99 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -69,7 +69,7 @@ func (gui *Gui) refreshBranches() { } gui.State.Branches = builder.Build() - if err := gui.postRefreshUpdate(gui.Contexts.Branches); err != nil { + if err := gui.postRefreshUpdate(gui.State.Contexts.Branches); err != nil { gui.Log.Error(err) } @@ -507,8 +507,8 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { context.GetPanelState().SetSelectedLineIdx(0) } - if context.GetKey() != gui.Contexts.Branches.GetKey() { - if err := gui.pushContext(gui.Contexts.Branches); err != nil { + if context.GetKey() != gui.State.Contexts.Branches.GetKey() { + if err := gui.pushContext(gui.State.Contexts.Branches); err != nil { return err } } diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 287410ba9..f0223a15e 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -107,7 +107,7 @@ func (gui *Gui) refreshCommitFilesView() error { } gui.State.CommitFileManager.SetFiles(files, to) - return gui.postRefreshUpdate(gui.Contexts.CommitFiles) + return gui.postRefreshUpdate(gui.State.Contexts.CommitFiles) } func (gui *Gui) handleOpenOldCommitFile() error { @@ -167,7 +167,7 @@ func (gui *Gui) handleToggleFileForPatch() error { gui.GitCommand.PatchManager.Reset() } - return gui.postRefreshUpdate(gui.Contexts.CommitFiles) + return gui.postRefreshUpdate(gui.State.Contexts.CommitFiles) } if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() { @@ -215,7 +215,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { } } - if err := gui.pushContext(gui.Contexts.PatchBuilding); err != nil { + if err := gui.pushContext(gui.State.Contexts.PatchBuilding); err != nil { return err } return gui.handleRefreshPatchBuildingPanel(selectedLineIdx) @@ -231,7 +231,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { return enterTheFile(selectedLineIdx) }, handleClose: func() error { - return gui.pushContext(gui.Contexts.CommitFiles) + return gui.pushContext(gui.State.Contexts.CommitFiles) }, }) } @@ -247,7 +247,7 @@ func (gui *Gui) handleToggleCommitFileDirCollapsed() error { gui.State.CommitFileManager.ToggleCollapsed(node.GetPath()) - if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles); err != nil { + if err := gui.postRefreshUpdate(gui.State.Contexts.CommitFiles); err != nil { gui.Log.Error(err) } @@ -262,14 +262,14 @@ func (gui *Gui) switchToCommitFilesContext(refName string, canRebase bool, conte gui.State.Panels.CommitFiles.SelectedLineIdx = 0 gui.State.Panels.CommitFiles.refName = refName gui.State.Panels.CommitFiles.canRebase = canRebase - gui.Contexts.CommitFiles.SetParentContext(context) - gui.Contexts.CommitFiles.SetWindowName(windowName) + gui.State.Contexts.CommitFiles.SetParentContext(context) + gui.State.Contexts.CommitFiles.SetWindowName(windowName) if err := gui.refreshCommitFilesView(); err != nil { return err } - return gui.pushContext(gui.Contexts.CommitFiles) + return gui.pushContext(gui.State.Contexts.CommitFiles) } // NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics @@ -283,15 +283,15 @@ func (gui *Gui) handleToggleCommitFileTreeView() error { gui.State.CommitFileManager.ExpandToPath(path) index, found := gui.State.CommitFileManager.GetIndexForPath(path) if found { - gui.Contexts.CommitFiles.GetPanelState().SetSelectedLineIdx(index) + gui.State.Contexts.CommitFiles.GetPanelState().SetSelectedLineIdx(index) } } if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY { - if err := gui.Contexts.CommitFiles.HandleRender(); err != nil { + if err := gui.State.Contexts.CommitFiles.HandleRender(); err != nil { return err } - if err := gui.Contexts.CommitFiles.HandleFocus(); err != nil { + if err := gui.State.Contexts.CommitFiles.HandleFocus(); err != nil { return err } } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 8edcc642d..4da9e1922 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -86,7 +86,7 @@ func (gui *Gui) refreshCommits() error { go utils.Safe(func() { _ = gui.refreshCommitsWithLimit() - context, ok := gui.Contexts.CommitFiles.GetParentContext() + context, ok := gui.State.Contexts.CommitFiles.GetParentContext() if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { // This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position. // However if we've just added a brand new commit, it pushes the list down by one and so we would end up @@ -127,7 +127,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { } gui.State.Commits = commits - return gui.postRefreshUpdate(gui.Contexts.BranchCommits) + return gui.postRefreshUpdate(gui.State.Contexts.BranchCommits) } func (gui *Gui) refreshRebaseCommits() error { @@ -142,7 +142,7 @@ func (gui *Gui) refreshRebaseCommits() error { } gui.State.Commits = updatedCommits - return gui.postRefreshUpdate(gui.Contexts.BranchCommits) + return gui.postRefreshUpdate(gui.State.Contexts.BranchCommits) } // specific functions @@ -444,7 +444,7 @@ func (gui *Gui) handleViewCommitFiles() error { return nil } - return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits, "commits") + return gui.switchToCommitFilesContext(commit.Sha, true, gui.State.Contexts.BranchCommits, "commits") } func (gui *Gui) handleCreateFixupCommit() error { diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index c52a32ce3..700fe298a 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -204,7 +204,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, f } gui.g.Update(func(g *gocui.Gui) error { - return gui.pushContext(gui.Contexts.Confirmation) + return gui.pushContext(gui.State.Contexts.Confirmation) }) return confirmationView, nil } @@ -284,7 +284,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { { viewName: "confirmation", key: gui.getKey(keybindingConfig.Universal.TogglePanel), - handler: func() error { return gui.replaceContext(gui.Contexts.Suggestions) }, + handler: func() error { return gui.replaceContext(gui.State.Contexts.Suggestions) }, }, { viewName: "suggestions", @@ -304,7 +304,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { { viewName: "suggestions", key: gui.getKey(keybindingConfig.Universal.TogglePanel), - handler: func() error { return gui.replaceContext(gui.Contexts.Confirmation) }, + handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) }, }, } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 82c89f535..8d2d92cc9 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -92,27 +92,27 @@ type ContextTree struct { func (gui *Gui) allContexts() []Context { return []Context{ - gui.Contexts.Status, - gui.Contexts.Files, - gui.Contexts.Submodules, - gui.Contexts.Branches, - gui.Contexts.Remotes, - gui.Contexts.RemoteBranches, - gui.Contexts.Tags, - gui.Contexts.BranchCommits, - gui.Contexts.CommitFiles, - gui.Contexts.ReflogCommits, - gui.Contexts.Stash, - gui.Contexts.Menu, - gui.Contexts.Confirmation, - gui.Contexts.Credentials, - gui.Contexts.CommitMessage, - gui.Contexts.Normal, - gui.Contexts.Staging, - gui.Contexts.Merging, - gui.Contexts.PatchBuilding, - gui.Contexts.SubCommits, - gui.Contexts.Suggestions, + gui.State.Contexts.Status, + gui.State.Contexts.Files, + gui.State.Contexts.Submodules, + gui.State.Contexts.Branches, + gui.State.Contexts.Remotes, + gui.State.Contexts.RemoteBranches, + gui.State.Contexts.Tags, + gui.State.Contexts.BranchCommits, + gui.State.Contexts.CommitFiles, + gui.State.Contexts.ReflogCommits, + gui.State.Contexts.Stash, + gui.State.Contexts.Menu, + gui.State.Contexts.Confirmation, + gui.State.Contexts.Credentials, + gui.State.Contexts.CommitMessage, + gui.State.Contexts.Normal, + gui.State.Contexts.Staging, + gui.State.Contexts.Merging, + gui.State.Contexts.PatchBuilding, + gui.State.Contexts.SubCommits, + gui.State.Contexts.Suggestions, } } @@ -279,20 +279,20 @@ func (gui *Gui) contextTree() ContextTree { } } -func (gui *Gui) initialViewContextMap() map[string]Context { +func (tree ContextTree) initialViewContextMap() map[string]Context { return map[string]Context{ - "status": gui.Contexts.Status, - "files": gui.Contexts.Files, - "branches": gui.Contexts.Branches, - "commits": gui.Contexts.BranchCommits, - "commitFiles": gui.Contexts.CommitFiles, - "stash": gui.Contexts.Stash, - "menu": gui.Contexts.Menu, - "confirmation": gui.Contexts.Confirmation, - "credentials": gui.Contexts.Credentials, - "commitMessage": gui.Contexts.CommitMessage, - "main": gui.Contexts.Normal, - "secondary": gui.Contexts.Normal, + "status": tree.Status, + "files": tree.Files, + "branches": tree.Branches, + "commits": tree.BranchCommits, + "commitFiles": tree.CommitFiles, + "stash": tree.Stash, + "menu": tree.Menu, + "confirmation": tree.Confirmation, + "credentials": tree.Credentials, + "commitMessage": tree.CommitMessage, + "main": tree.Normal, + "secondary": tree.Normal, } } @@ -307,46 +307,46 @@ func (gui *Gui) popupViewNames() []string { return result } -func (gui *Gui) initialViewTabContextMap() map[string][]tabContext { +func (tree ContextTree) initialViewTabContextMap() map[string][]tabContext { return map[string][]tabContext{ "branches": { { tab: "Local Branches", - contexts: []Context{gui.Contexts.Branches}, + contexts: []Context{tree.Branches}, }, { tab: "Remotes", contexts: []Context{ - gui.Contexts.Remotes, - gui.Contexts.RemoteBranches, + tree.Remotes, + tree.RemoteBranches, }, }, { tab: "Tags", - contexts: []Context{gui.Contexts.Tags}, + contexts: []Context{tree.Tags}, }, }, "commits": { { tab: "Commits", - contexts: []Context{gui.Contexts.BranchCommits}, + contexts: []Context{tree.BranchCommits}, }, { tab: "Reflog", contexts: []Context{ - gui.Contexts.ReflogCommits, + tree.ReflogCommits, }, }, }, "files": { { tab: "Files", - contexts: []Context{gui.Contexts.Files}, + contexts: []Context{tree.Files}, }, { tab: "Submodules", contexts: []Context{ - gui.Contexts.Submodules, + tree.Submodules, }, }, }, @@ -604,9 +604,10 @@ func (gui *Gui) currentSideContext() *ListContext { } func (gui *Gui) defaultSideContext() Context { - return gui.Contexts.Files + return gui.State.Contexts.Files } +// remove the need to do this: always use a mapping func (gui *Gui) setInitialViewContexts() { // arguably we should only have our ViewContextMap and we should do away with // contexts on views, or vice versa @@ -665,7 +666,7 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error { if v.Name() == "commitFiles" && newView.Name() != "main" && newView.Name() != "secondary" { gui.resetWindowForView("commitFiles") - if err := gui.deactivateContext(gui.Contexts.CommitFiles); err != nil { + if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil { return err } } diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go index 2f2585bcf..3410d3dee 100644 --- a/pkg/gui/credentials_panel.go +++ b/pkg/gui/credentials_panel.go @@ -26,7 +26,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string { credentialsView.Mask = '*' } - if err := gui.pushContext(gui.Contexts.Credentials); err != nil { + if err := gui.pushContext(gui.State.Contexts.Credentials); err != nil { return err } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 5a7ee6c66..2e90818be 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -1,12 +1,6 @@ package gui import ( - - // "io" - // "io/ioutil" - - // "strings" - "fmt" "regexp" "strings" @@ -124,13 +118,13 @@ func (gui *Gui) refreshFilesAndSubmodules() error { } gui.g.Update(func(g *gocui.Gui) error { - if err := gui.postRefreshUpdate(gui.Contexts.Submodules); err != nil { + if err := gui.postRefreshUpdate(gui.State.Contexts.Submodules); err != nil { gui.Log.Error(err) } if gui.getFilesView().Context == FILES_CONTEXT_KEY { // doing this a little custom (as opposed to using gui.postRefreshUpdate) because we handle selecting the file explicitly below - if err := gui.Contexts.Files.HandleRender(); err != nil { + if err := gui.State.Contexts.Files.HandleRender(); err != nil { return err } } @@ -210,7 +204,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error if file.HasMergeConflicts { return gui.createErrorPanel(gui.Tr.FileStagingRequirements) } - _ = gui.pushContext(gui.Contexts.Staging) + _ = gui.pushContext(gui.State.Contexts.Staging) return gui.handleRefreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code } @@ -412,7 +406,7 @@ func (gui *Gui) handleCommitPress() error { } gui.g.Update(func(g *gocui.Gui) error { - if err := gui.pushContext(gui.Contexts.CommitMessage); err != nil { + if err := gui.pushContext(gui.State.Contexts.CommitMessage); err != nil { return err } @@ -777,7 +771,7 @@ func (gui *Gui) handleSwitchToMerge() error { return gui.createErrorPanel(gui.Tr.FileNoMergeCons) } - return gui.pushContext(gui.Contexts.Merging) + return gui.pushContext(gui.State.Contexts.Merging) } func (gui *Gui) openFile(filename string) error { @@ -842,7 +836,7 @@ func (gui *Gui) handleToggleDirCollapsed() error { gui.State.FileManager.ToggleCollapsed(node.GetPath()) - if err := gui.postRefreshUpdate(gui.Contexts.Files); err != nil { + if err := gui.postRefreshUpdate(gui.State.Contexts.Files); err != nil { gui.Log.Error(err) } @@ -865,10 +859,10 @@ func (gui *Gui) handleToggleFileTreeView() error { } if gui.getFilesView().Context == FILES_CONTEXT_KEY { - if err := gui.Contexts.Files.HandleRender(); err != nil { + if err := gui.State.Contexts.Files.HandleRender(); err != nil { return err } - if err := gui.Contexts.Files.HandleFocus(); err != nil { + if err := gui.State.Contexts.Files.HandleFocus(); err != nil { return err } } diff --git a/pkg/gui/filtering.go b/pkg/gui/filtering.go index b3fa0e089..1f5c5032a 100644 --- a/pkg/gui/filtering.go +++ b/pkg/gui/filtering.go @@ -32,11 +32,11 @@ func (gui *Gui) setFiltering(path string) error { gui.State.ScreenMode = SCREEN_HALF } - if err := gui.pushContext(gui.Contexts.BranchCommits); err != nil { + if err := gui.pushContext(gui.State.Contexts.BranchCommits); err != nil { return err } return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS}, then: func() { - gui.Contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + gui.State.Contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) }}) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index dd2b38c26..b9d574623 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -64,12 +64,16 @@ type Repo string // Gui wraps the gocui Gui object which handles rendering and events type Gui struct { - g *gocui.Gui - Log *logrus.Entry - GitCommand *commands.GitCommand - OSCommand *oscommands.OSCommand - SubProcess *exec.Cmd - State *guiState + g *gocui.Gui + Log *logrus.Entry + GitCommand *commands.GitCommand + OSCommand *oscommands.OSCommand + + // this is the state of the GUI for the current repo + State *guiState + + // this is a mapping of repos to gui states, so that we can restore the original + // gui state when returning from a subrepo RepoStateMap map[Repo]*guiState Config config.AppConfigurer Tr *i18n.TranslationSet @@ -85,7 +89,6 @@ type Gui struct { // when lazygit is opened outside a git directory we want to open to the most // recent repo with the recent repos popup showing showRecentRepos bool - Contexts ContextTree // this array either includes the events that we're recording in this session // or the events we've recorded in a prior session @@ -101,6 +104,9 @@ type Gui struct { // when you enter into a submodule we'll append the superproject's path to this array // so that you can return to the superproject RepoPathStack []string + + // this tells us whether our views have been initially set up + ViewsSetup bool } type RecordedEvent struct { @@ -317,6 +323,7 @@ type guiState struct { Modes Modes ContextManager ContextManager + Contexts ContextTree ViewContextMap map[string]Context ViewTabContextMap map[string][]tabContext @@ -325,7 +332,9 @@ type guiState struct { // side windows we need to know which view to give focus to for a given window WindowViewNameMap map[string]string - // tells us whether we've set up our views. We only do this once per repo + // tells us whether we've set up our views for the current repo. We'll need to + // do this whenever we switch back and forth between repos to get the views + // back in sync with the repo state ViewsSetup bool } @@ -334,6 +343,7 @@ func (gui *Gui) resetState(filterPath string) { if err == nil { if state := gui.RepoStateMap[Repo(currentDir)]; state != nil { gui.State = state + gui.State.ViewsSetup = false return } } else { @@ -347,6 +357,8 @@ func (gui *Gui) resetState(filterPath string) { screenMode = SCREEN_HALF } + contexts := gui.contextTree() + gui.State = &guiState{ FileManager: filetree.NewFileManager(make([]*models.File, 0), gui.Log, showTree), CommitFileManager: filetree.NewCommitFileManager(make([]*models.CommitFile, 0), gui.Log, showTree), @@ -387,13 +399,15 @@ func (gui *Gui) resetState(filterPath string) { }, Diffing: Diffing{}, }, - ViewContextMap: gui.initialViewContextMap(), - ViewTabContextMap: gui.initialViewTabContextMap(), + ViewContextMap: contexts.initialViewContextMap(), + ViewTabContextMap: contexts.initialViewTabContextMap(), ScreenMode: screenMode, - ContextManager: NewContextManager(gui.Contexts), + // TODO: put contexts in the context manager + ContextManager: NewContextManager(contexts), + Contexts: contexts, } - gui.RepoStateMap[Repo(gui.GitCommand.DotGitDir)] = gui.State + gui.RepoStateMap[Repo(currentDir)] = gui.State } // for now the split view will always be on @@ -414,7 +428,6 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom RepoStateMap: map[Repo]*guiState{}, } - gui.Contexts = gui.contextTree() gui.resetState(filterPath) gui.watchFilesForChanges() @@ -472,11 +485,6 @@ func (gui *Gui) Run() error { go utils.Safe(gui.startBackgroundFetch) } - go func() { - gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false) - gui.waitForIntro.Done() - }() - gui.goEvery(time.Second*time.Duration(userConfig.Refresher.RefreshInterval), gui.stopChan, gui.refreshFilesAndSubmodules) g.SetManager(gocui.ManagerFunc(gui.layout), gocui.ManagerFunc(gui.getFocusLayout())) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 3ebceaa9e..d49151cfb 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1706,7 +1706,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideWindow(window)}) } - for viewName := range gui.initialViewTabContextMap() { + for viewName := range gui.State.Contexts.initialViewTabContextMap() { bindings = append(bindings, []*Binding{ { ViewName: viewName, @@ -1741,7 +1741,7 @@ func (gui *Gui) keybindings() error { } } - for viewName := range gui.initialViewTabContextMap() { + for viewName := range gui.State.Contexts.initialViewTabContextMap() { viewName := viewName tabClickCallback := func(tabIndex int) error { return gui.onViewTabClick(viewName, tabIndex) } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index a60a137af..6d1c956d3 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -152,7 +152,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { branchesView.ContainsList = true } - commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.GetWindowName(), true) + commitFilesView, err := setViewFromDimensions("commitFiles", gui.State.Contexts.CommitFiles.GetWindowName(), true) if err != nil { if err.Error() != UNKNOWN_VIEW_ERROR_MSG { return err @@ -266,23 +266,20 @@ func (gui *Gui) layout(g *gocui.Gui) error { gui.State.OldInformation = informationStr } - if !gui.State.ViewsSetup { + if !gui.ViewsSetup { if err := gui.onInitialViewsCreation(); err != nil { return err } - gui.State.ViewsSetup = true + gui.ViewsSetup = true } - if gui.g.CurrentView() == nil { - initialContext := gui.Contexts.Files - if gui.State.Modes.Filtering.Active() { - initialContext = gui.Contexts.BranchCommits - } - - if err := gui.pushContext(initialContext); err != nil { + if !gui.State.ViewsSetup { + if err := gui.onInitialViewsCreationForRepo(); err != nil { return err } + + gui.State.ViewsSetup = true } for _, listContext := range gui.getListContexts() { @@ -323,7 +320,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { return gui.resizeCurrentPopupPanel() } -func (gui *Gui) onInitialViewsCreation() error { +func (gui *Gui) onInitialViewsCreationForRepo() error { gui.setInitialViewContexts() // hide any popup views. This only applies when we've just switched repos @@ -331,6 +328,28 @@ func (gui *Gui) onInitialViewsCreation() error { _, _ = gui.g.SetViewOnBottom(viewName) } + // the status panel is not actually a list context at the moment, so it is excluded + // here. Arguably that's quite convenient because it means we're back to starting + // in the files panel when landing in a new repo, but when returning from a submodule + // we'll be back in the submodules context. This still seems awkward though, and it's + // definitely going to break when (if) we make the status context a list context + initialContext := gui.currentSideContext() + if initialContext == nil { + if gui.State.Modes.Filtering.Active() { + initialContext = gui.State.Contexts.BranchCommits + } else { + initialContext = gui.State.Contexts.Files + } + } + + if err := gui.pushContext(initialContext); err != nil { + return err + } + + return gui.loadNewRepo() +} + +func (gui *Gui) onInitialViewsCreation() error { gui.g.Mutexes.ViewsMutex.Lock() // add tabs to views for _, view := range gui.g.Views() { @@ -342,10 +361,6 @@ func (gui *Gui) onInitialViewsCreation() error { } |