Repository: jesseduffield/lazygit
File: pkg/gui/controllers/status_controller.go (Go)

Code before:

func (self *StatusController) GetOnRenderToMain() func() error {
	config := self.c.UserConfig.Gui

	switch config.DefaultMainView {
	case "dashboard":
		return self.showDashboard
	case "allBranchesLog":
		return self.showAllBranchLogs
	default:
		return self.showDashboard
	}
}

func (self *StatusController) GetOnClick() func() error {
	return self.onClick
}

func (self *StatusController) Context() types.Context {
	return self.c.Contexts().Status
}

func (self *StatusController) onClick() error {
	// TODO: move into some abstraction (status is currently not a listViewContext where a lot of this code lives)
	currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()
	if currentBranch == nil {
		// need to wait for branches to refresh
		return nil
	}

	if err := self.c.PushContext(self.Context()); err != nil {
		return err
	}

	cx, _ := self.c.Views().Status.Cursor()
	upstreamStatus := presentation.BranchStatus(currentBranch, types.ItemOperationNone, self.c.Tr, time.Now())
	repoName := self.c.Git().RepoPaths.RepoName()
	workingTreeState := self.c.Git().Status.WorkingTreeState()
	switch workingTreeState {
	case enums.REBASE_MODE_REBASING, enums.REBASE_MODE_MERGING:
		workingTreeStatus := fmt.Sprintf("(%s)", presentation.FormatWorkingTreeStateLower(self.c.Tr, workingTreeState))
		if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) {
			return self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu()
		}
		if cursorInSubstring(cx, upstreamStatus+" "+workingTreeStatus+" ", repoName) {
			return self.c.Helpers().Repos.CreateRecentReposMenu()
		}
	default:
		if cursorInSubstring(cx, upstreamStatus+" ", repoName) {
			return self.c.Helpers().Repos.CreateRecentReposMenu()
		}

Review comment (suggestion):
I am also not sure if we should be quietly choosing the dashboard view in case of an error in the config file.

Code after:
}

func (self *StatusController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
	return []*gocui.ViewMouseBinding{
		{
			ViewName: "main",
			Key:      gocui.MouseLeft,
			Handler:  self.onClickMain,
		},
	}
}

func (self *StatusController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
	return self.c.HandleGenericClick(self.c.Views().Main)
}

func (self *StatusController) GetOnRenderToMain() func() error {
	config := self.c.UserConfig.Gui

	switch config.StatusPanelView {
	case "dashboard":
		return self.showDashboard
	case "allBranchesLog":
		return self.showAllBranchLogs
	default:
		return self.showDashboard
	}
}

func (self *StatusController) GetOnClick() func() error {
	return self.onClick
}

func (self *StatusController) Context() types.Context {
	return self.c.Contexts().Status
}

func (self *StatusController) onClick() error {
	// TODO: move into some abstraction (status is currently not a listViewContext where a lot of this code lives)
	currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()
	if currentBranch == nil {
		// need to wait for branches to refresh
		return nil
	}

	if err := self.c.PushContext(self.Context()); err != nil {
		return err
	}

	cx, _ := self.c.Views().Status.Cursor()
	upstreamStatus := presentation.BranchStatus(currentBranch, types.ItemOperationNone, self.c.Tr, time.Now(), self.c.UserConfig)