1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-12 04:23:03 +02:00

more removing of g and v

This commit is contained in:
Jesse Duffield 2020-08-15 17:01:43 +10:00
parent 63e6eea9ec
commit 15229bbdab
11 changed files with 44 additions and 50 deletions

View File

@ -18,13 +18,13 @@ func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
func (gui *Gui) handleCommitFilesClick(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitFilesClick(g *gocui.Gui, v *gocui.View) error {
itemCount := len(gui.State.CommitFiles) itemCount := len(gui.State.CommitFiles)
handleSelect := gui.handleCommitFileSelect handleSelect := gui.wrappedHandler(gui.handleCommitFileSelect)
selectedLine := &gui.State.Panels.CommitFiles.SelectedLine selectedLine := &gui.State.Panels.CommitFiles.SelectedLine
return gui.handleClick(v, itemCount, selectedLine, handleSelect) return gui.handleClick(v, itemCount, selectedLine, handleSelect)
} }
func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitFileSelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil
} }
@ -44,7 +44,7 @@ func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error {
return err return err
} }
v.FocusPoint(0, gui.State.Panels.CommitFiles.SelectedLine) gui.getCommitFilesView().FocusPoint(0, gui.State.Panels.CommitFiles.SelectedLine)
cmd := gui.OSCommand.ExecutableFromString( cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCommitFileCmdStr(commitFile.Sha, commitFile.Name, false), gui.GitCommand.ShowCommitFileCmdStr(commitFile.Sha, commitFile.Name, false),
@ -122,7 +122,7 @@ func (gui *Gui) refreshCommitFilesView() error {
displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref) displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsFileView, displayStrings) gui.renderDisplayStrings(commitsFileView, displayStrings)
return gui.handleCommitFileSelect(gui.g, commitsFileView) return gui.handleCommitFileSelect()
} }
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
@ -251,5 +251,5 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
func (gui *Gui) onCommitFilesPanelSearchSelect(selectedLine int) error { func (gui *Gui) onCommitFilesPanelSearchSelect(selectedLine int) error {
gui.State.Panels.CommitFiles.SelectedLine = selectedLine gui.State.Panels.CommitFiles.SelectedLine = selectedLine
return gui.handleCommitFileSelect(gui.g, gui.getCommitFilesView()) return gui.handleCommitFileSelect()
} }

View File

@ -56,8 +56,8 @@ func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error {
return gui.switchFocus(v, gui.getFilesView()) return gui.switchFocus(v, gui.getFilesView())
} }
func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitFocused() error {
if _, err := g.SetViewOnTop("commitMessage"); err != nil { if _, err := gui.g.SetViewOnTop("commitMessage"); err != nil {
return err return err
} }

View File

@ -21,7 +21,7 @@ func (gui *Gui) getSelectedCommit() *commands.Commit {
return gui.State.Commits[selectedLine] return gui.State.Commits[selectedLine]
} }
func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitSelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil
} }
@ -31,7 +31,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
return err return err
} }
if _, err := gui.g.SetCurrentView(v.Name()); err != nil { if _, err := gui.g.SetCurrentView("commits"); err != nil {
return err return err
} }
@ -54,7 +54,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
return gui.newStringTask("main", gui.Tr.SLocalize("NoCommitsThisBranch")) return gui.newStringTask("main", gui.Tr.SLocalize("NoCommitsThisBranch"))
} }
v.FocusPoint(0, gui.State.Panels.Commits.SelectedLine) gui.getCommitsView().FocusPoint(0, gui.State.Panels.Commits.SelectedLine)
if gui.inDiffMode() { if gui.inDiffMode() {
return gui.renderDiff() return gui.renderDiff()
@ -637,7 +637,7 @@ func (gui *Gui) renderBranchCommitsWithSelection() error {
displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref) displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsView, displayStrings) gui.renderDisplayStrings(commitsView, displayStrings)
if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" { if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" {
if err := gui.handleCommitSelect(gui.g, commitsView); err != nil { if err := gui.handleCommitSelect(); err != nil {
return err return err
} }
} }
@ -709,10 +709,10 @@ func (gui *Gui) onCommitsPanelSearchSelect(selectedLine int) error {
switch commitsView.Context { switch commitsView.Context {
case "branch-commits": case "branch-commits":
gui.State.Panels.Commits.SelectedLine = selectedLine gui.State.Panels.Commits.SelectedLine = selectedLine
return gui.handleCommitSelect(gui.g, commitsView) return gui.handleCommitSelect()
case "reflog-commits": case "reflog-commits":
gui.State.Panels.ReflogCommits.SelectedLine = selectedLine gui.State.Panels.ReflogCommits.SelectedLine = selectedLine
return gui.handleReflogCommitSelect(gui.g, commitsView) return gui.handleReflogCommitSelect()
} }
return nil return nil
} }

View File

@ -60,8 +60,8 @@ func (gui *Gui) handleCloseCredentialsView(g *gocui.Gui, v *gocui.View) error {
return gui.switchFocus(nil, gui.getFilesView()) return gui.switchFocus(nil, gui.getFilesView())
} }
func (gui *Gui) handleCredentialsViewFocused(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCredentialsViewFocused() error {
if _, err := g.SetViewOnTop("credentials"); err != nil { if _, err := gui.g.SetViewOnTop("credentials"); err != nil {
return err return err
} }

View File

@ -1333,12 +1333,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleSetBranchUpstream, Handler: gui.handleSetBranchUpstream,
Description: gui.Tr.SLocalize("setUpstream"), Description: gui.Tr.SLocalize("setUpstream"),
}, },
{
ViewName: "stash",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleStashEntrySelect,
},
{ {
ViewName: "status", ViewName: "status",
Key: gocui.MouseLeft, Key: gocui.MouseLeft,

View File

@ -163,8 +163,8 @@ func (gui *Gui) getListViews() []*listView {
context: "tags", context: "tags",
getItemsLength: func() int { return len(gui.State.Tags) }, getItemsLength: func() int { return len(gui.State.Tags) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine },
handleFocus: gui.handleTagSelect, handleFocus: gui.wrappedHandler(gui.handleTagSelect),
handleItemSelect: gui.handleTagSelect, handleItemSelect: gui.wrappedHandler(gui.handleTagSelect),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },
@ -174,8 +174,8 @@ func (gui *Gui) getListViews() []*listView {
context: "branch-commits", context: "branch-commits",
getItemsLength: func() int { return len(gui.State.Commits) }, getItemsLength: func() int { return len(gui.State.Commits) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine },
handleFocus: gui.handleCommitSelect, handleFocus: gui.wrappedHandler(gui.handleCommitSelect),
handleItemSelect: gui.handleCommitSelect, handleItemSelect: gui.wrappedHandler(gui.handleCommitSelect),
handleClickSelectedItem: gui.handleSwitchToCommitFilesPanel, handleClickSelectedItem: gui.handleSwitchToCommitFilesPanel,
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
@ -185,8 +185,8 @@ func (gui *Gui) getListViews() []*listView {
context: "reflog-commits", context: "reflog-commits",
getItemsLength: func() int { return len(gui.State.FilteredReflogCommits) }, getItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
handleFocus: gui.handleReflogCommitSelect, handleFocus: gui.wrappedHandler(gui.handleReflogCommitSelect),
handleItemSelect: gui.handleReflogCommitSelect, handleItemSelect: gui.wrappedHandler(gui.handleReflogCommitSelect),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },
@ -194,8 +194,8 @@ func (gui *Gui) getListViews() []*listView {
viewName: "stash", viewName: "stash",
getItemsLength: func() int { return len(gui.State.StashEntries) }, getItemsLength: func() int { return len(gui.State.StashEntries) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine },
handleFocus: gui.handleStashEntrySelect, handleFocus: gui.wrappedHandler(gui.handleStashEntrySelect),
handleItemSelect: gui.handleStashEntrySelect, handleItemSelect: gui.wrappedHandler(gui.handleStashEntrySelect),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },
@ -203,8 +203,8 @@ func (gui *Gui) getListViews() []*listView {
viewName: "commitFiles", viewName: "commitFiles",
getItemsLength: func() int { return len(gui.State.CommitFiles) }, getItemsLength: func() int { return len(gui.State.CommitFiles) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
handleFocus: gui.handleCommitFileSelect, handleFocus: gui.wrappedHandler(gui.handleCommitFileSelect),
handleItemSelect: gui.handleCommitFileSelect, handleItemSelect: gui.wrappedHandler(gui.handleCommitFileSelect),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },

View File

@ -18,14 +18,14 @@ func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
return reflogComits[selectedLine] return reflogComits[selectedLine]
} }
func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleReflogCommitSelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil
} }
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView(v.Name()); err != nil { if _, err := gui.g.SetCurrentView("commits"); err != nil {
return err return err
} }
@ -35,7 +35,7 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
if commit == nil { if commit == nil {
return gui.newStringTask("main", "No reflog history") return gui.newStringTask("main", "No reflog history")
} }
v.FocusPoint(0, gui.State.Panels.ReflogCommits.SelectedLine) gui.getCommitsView().FocusPoint(0, gui.State.Panels.ReflogCommits.SelectedLine)
if gui.inDiffMode() { if gui.inDiffMode() {
return gui.renderDiff() return gui.renderDiff()
@ -107,7 +107,7 @@ func (gui *Gui) renderReflogCommitsWithSelection() error {
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref) displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsView, displayStrings) gui.renderDisplayStrings(commitsView, displayStrings)
if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" { if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" {
if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil { if err := gui.handleReflogCommitSelect(); err != nil {
return err return err
} }
} }

View File

@ -28,7 +28,7 @@ func (gui *Gui) resetToRef(ref string, strength string, options commands.RunComm
return err return err
} }
return gui.handleCommitSelect(gui.g, gui.getCommitsView()) return gui.handleCommitSelect()
} }
func (gui *Gui) createResetMenu(ref string) error { func (gui *Gui) createResetMenu(ref string) error {

View File

@ -17,14 +17,14 @@ func (gui *Gui) getSelectedStashEntry() *commands.StashEntry {
return gui.State.StashEntries[selectedLine] return gui.State.StashEntries[selectedLine]
} }
func (gui *Gui) handleStashEntrySelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleStashEntrySelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil
} }
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView(v.Name()); err != nil { if _, err := gui.g.SetCurrentView("stash"); err != nil {
return err return err
} }
@ -34,7 +34,7 @@ func (gui *Gui) handleStashEntrySelect(g *gocui.Gui, v *gocui.View) error {
if stashEntry == nil { if stashEntry == nil {
return gui.newStringTask("main", gui.Tr.SLocalize("NoStashEntries")) return gui.newStringTask("main", gui.Tr.SLocalize("NoStashEntries"))
} }
v.FocusPoint(0, gui.State.Panels.Stash.SelectedLine) gui.getStashView().FocusPoint(0, gui.State.Panels.Stash.SelectedLine)
if gui.inDiffMode() { if gui.inDiffMode() {
return gui.renderDiff() return gui.renderDiff()
@ -152,5 +152,5 @@ func (gui *Gui) handleStashSave(stashFunc func(message string) error) error {
func (gui *Gui) onStashPanelSearchSelect(selectedLine int) error { func (gui *Gui) onStashPanelSearchSelect(selectedLine int) error {
gui.State.Panels.Stash.SelectedLine = selectedLine gui.State.Panels.Stash.SelectedLine = selectedLine
return gui.handleStashEntrySelect(gui.g, gui.getStashView()) return gui.handleStashEntrySelect()
} }

View File

@ -17,14 +17,14 @@ func (gui *Gui) getSelectedTag() *commands.Tag {
return gui.State.Tags[selectedLine] return gui.State.Tags[selectedLine]
} }
func (gui *Gui) handleTagSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleTagSelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil
} }
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView(v.Name()); err != nil { if _, err := gui.g.SetCurrentView("branches"); err != nil {
return err return err
} }
@ -34,7 +34,7 @@ func (gui *Gui) handleTagSelect(g *gocui.Gui, v *gocui.View) error {
if tag == nil { if tag == nil {
return gui.newStringTask("main", "No tags") return gui.newStringTask("main", "No tags")
} }
v.FocusPoint(0, gui.State.Panels.Tags.SelectedLine) gui.getBranchesView().FocusPoint(0, gui.State.Panels.Tags.SelectedLine)
if gui.inDiffMode() { if gui.inDiffMode() {
return gui.renderDiff() return gui.renderDiff()
@ -72,7 +72,7 @@ func (gui *Gui) renderTagsWithSelection() error {
displayStrings := presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref) displayStrings := presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
gui.renderDisplayStrings(branchesView, displayStrings) gui.renderDisplayStrings(branchesView, displayStrings)
if gui.g.CurrentView() == branchesView && branchesView.Context == "tags" { if gui.g.CurrentView() == branchesView && branchesView.Context == "tags" {
if err := gui.handleTagSelect(gui.g, branchesView); err != nil { if err := gui.handleTagSelect(); err != nil {
return gui.surfaceError(err) return gui.surfaceError(err)
} }
} }

View File

@ -234,22 +234,22 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
case "remote-branches": case "remote-branches":
return gui.handleRemoteBranchSelect() return gui.handleRemoteBranchSelect()
case "tags": case "tags":
return gui.handleTagSelect(g, v) return gui.handleTagSelect()
default: default:
return errors.New("unknown branches panel context: " + branchesView.Context) return errors.New("unknown branches panel context: " + branchesView.Context)
} }
case "commits": case "commits":
return gui.handleCommitSelect(g, v) return gui.handleCommitSelect()
case "commitFiles": case "commitFiles":
return gui.handleCommitFileSelect(g, v) return gui.handleCommitFileSelect()
case "stash": case "stash":
return gui.handleStashEntrySelect(g, v) return gui.handleStashEntrySelect()
case "confirmation": case "confirmation":
return nil return nil
case "commitMessage": case "commitMessage":
return gui.handleCommitFocused(g, v) return gui.handleCommitFocused()
case "credentials": case "credentials":
return gui.handleCredentialsViewFocused(g, v) return gui.handleCredentialsViewFocused()
case "main": case "main":
if gui.State.MainContext == "merging" { if gui.State.MainContext == "merging" {
return gui.refreshMergePanel() return gui.refreshMergePanel()