From e4beaf4de96afee804d019e7c19eee833d3b1801 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 19 Aug 2020 19:26:05 +1000 Subject: [PATCH] more stuff --- pkg/gui/branches_panel.go | 17 +++++++-------- pkg/gui/commits_panel.go | 43 -------------------------------------- pkg/gui/global_handlers.go | 28 ++++++++----------------- pkg/gui/keybindings.go | 12 +++++------ 4 files changed, 23 insertions(+), 77 deletions(-) diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 59a1e9f8f..80e7e154a 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -439,23 +439,22 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { return nil } -func (gui *Gui) onBranchesTabClick(tabIndex int) error { - branchesView := gui.getBranchesView() - branchesView.TabIndex = tabIndex - - context := gui.ViewTabContextMap["branches"][tabIndex].contexts[0] +func (gui *Gui) onViewTabClick(viewName string, tabIndex int) error { + context := gui.ViewTabContextMap[viewName][tabIndex].contexts[0] return gui.switchContext(context) } -func (gui *Gui) handleNextBranchesTab(g *gocui.Gui, v *gocui.View) error { - return gui.onBranchesTabClick( +func (gui *Gui) handleNextTab(g *gocui.Gui, v *gocui.View) error { + return gui.onViewTabClick( + v.Name(), utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)), ) } -func (gui *Gui) handlePrevBranchesTab(g *gocui.Gui, v *gocui.View) error { - return gui.onBranchesTabClick( +func (gui *Gui) handlePrevTab(g *gocui.Gui, v *gocui.View) error { + return gui.onViewTabClick( + v.Name(), utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)), ) } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 1103b6867..7f6e0a5e4 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/presentation" - "github.com/jesseduffield/lazygit/pkg/utils" ) // list panel functions @@ -633,40 +632,10 @@ func (gui *Gui) renderBranchCommitsWithSelection() error { gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits)) displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref) gui.renderDisplayStrings(commitsView, displayStrings) - if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" { - if err := gui.handleCommitSelect(); err != nil { - return err - } - } return nil } -func (gui *Gui) onCommitsTabClick(tabIndex int) error { - contexts := []string{"branch-commits", "reflog-commits"} - commitsView := gui.getCommitsView() - commitsView.TabIndex = tabIndex - - return gui.switchCommitsPanelContext(contexts[tabIndex]) -} - -func (gui *Gui) switchCommitsPanelContext(context string) error { - commitsView := gui.getCommitsView() - commitsView.Context = context - if err := gui.onSearchEscape(); err != nil { - return err - } - - contextTabIndexMap := map[string]int{ - "branch-commits": 0, - "reflog-commits": 1, - } - - commitsView.TabIndex = contextTabIndexMap[context] - - return gui.refreshCommitsViewWithSelection() -} - func (gui *Gui) refreshCommitsViewWithSelection() error { commitsView := gui.getCommitsView() @@ -680,18 +649,6 @@ func (gui *Gui) refreshCommitsViewWithSelection() error { return nil } -func (gui *Gui) handleNextCommitsTab(g *gocui.Gui, v *gocui.View) error { - return gui.onCommitsTabClick( - utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)), - ) -} - -func (gui *Gui) handlePrevCommitsTab(g *gocui.Gui, v *gocui.View) error { - return gui.onCommitsTabClick( - utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)), - ) -} - func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { commit := gui.getSelectedCommit() if commit == nil { diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index d37fb8dea..41c4895ff 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -11,18 +11,8 @@ import ( // these views need to be re-rendered when the screen mode changes. The commits view, // for example, will show authorship information in half and full screen mode. -func (gui *Gui) viewsWithScreenModeDependentContent() []string { - return []string{"branches", "commits"} -} - -func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { - gui.State.ScreenMode = utils.NextIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) - // commits render differently depending on whether we're in fullscreen more or not - if err := gui.refreshCommitsViewWithSelection(); err != nil { - return err - } - - for _, viewName := range gui.viewsWithScreenModeDependentContent() { +func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error { + for _, viewName := range []string{"branches", "commits"} { if err := gui.rerenderView(viewName); err != nil { return err } @@ -31,16 +21,16 @@ func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { return nil } +func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { + gui.State.ScreenMode = utils.NextIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + + return gui.rerenderViewsWithScreenModeDependentContent() +} + func (gui *Gui) prevScreenMode(g *gocui.Gui, v *gocui.View) error { gui.State.ScreenMode = utils.PrevIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) - for _, viewName := range gui.viewsWithScreenModeDependentContent() { - if err := gui.rerenderView(viewName); err != nil { - return err - } - } - - return nil + return gui.rerenderViewsWithScreenModeDependentContent() } func (gui *Gui) scrollUpView(viewName string) error { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 227799b5c..7417d6782 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -593,13 +593,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { { ViewName: "branches", Key: gui.getKey("universal.nextTab"), - Handler: gui.handleNextBranchesTab, + Handler: gui.handleNextTab, Description: gui.Tr.SLocalize("nextTab"), }, { ViewName: "branches", Key: gui.getKey("universal.prevTab"), - Handler: gui.handlePrevBranchesTab, + Handler: gui.handlePrevTab, Description: gui.Tr.SLocalize("prevTab"), }, { @@ -626,13 +626,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { { ViewName: "commits", Key: gui.getKey("universal.nextTab"), - Handler: gui.handleNextCommitsTab, + Handler: gui.handleNextTab, Description: gui.Tr.SLocalize("nextTab"), }, { ViewName: "commits", Key: gui.getKey("universal.prevTab"), - Handler: gui.handlePrevCommitsTab, + Handler: gui.handlePrevTab, Description: gui.Tr.SLocalize("prevTab"), }, { @@ -1415,8 +1415,8 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { } tabClickBindings := map[string]func(int) error{ - "branches": gui.onBranchesTabClick, - "commits": gui.onCommitsTabClick, + "branches": func(tabIndex int) error { return gui.onViewTabClick("branches", tabIndex) }, + "commits": func(tabIndex int) error { return gui.onViewTabClick("commits", tabIndex) }, } for viewName, binding := range tabClickBindings {