1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00

ensure there is always a current context

This commit is contained in:
Jesse Duffield 2020-08-23 10:17:17 +10:00
parent ade54b38c1
commit 4198bbae6c
4 changed files with 5 additions and 16 deletions

View File

@ -85,7 +85,7 @@ func (gui *Gui) refreshCommits() error {
go func() { go func() {
_ = gui.refreshCommitsWithLimit() _ = gui.refreshCommitsWithLimit()
if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey()) { if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey()) {
_ = gui.refreshCommitFilesView() _ = gui.refreshCommitFilesView()
} }
wg.Done() wg.Done()

View File

@ -493,20 +493,9 @@ func (gui *Gui) renderContextStack() string {
return result return result
} }
func (gui *Gui) currentContextKey() string {
currentContext := gui.currentContext()
if currentContext == nil {
return ""
}
return currentContext.GetKey()
}
func (gui *Gui) currentContext() Context { func (gui *Gui) currentContext() Context {
// on startup the stack can be empty so we'll return an empty string in that case
if len(gui.State.ContextStack) == 0 { if len(gui.State.ContextStack) == 0 {
return nil return gui.defaultSideContext()
} }
return gui.State.ContextStack[len(gui.State.ContextStack)-1] return gui.State.ContextStack[len(gui.State.ContextStack)-1]

View File

@ -31,7 +31,7 @@ func (gui *Gui) renderDiff() error {
// which becomes an option when you bring up the diff menu, but when you're just // which becomes an option when you bring up the diff menu, but when you're just
// flicking through branches it will be using the local branch name. // flicking through branches it will be using the local branch name.
func (gui *Gui) currentDiffTerminals() []string { func (gui *Gui) currentDiffTerminals() []string {
switch gui.currentContextKey() { switch gui.currentContext().GetKey() {
case "": case "":
return nil return nil
case FILES_CONTEXT_KEY: case FILES_CONTEXT_KEY:
@ -71,7 +71,7 @@ func (gui *Gui) currentDiffTerminal() string {
} }
func (gui *Gui) currentlySelectedFilename() string { func (gui *Gui) currentlySelectedFilename() string {
switch gui.currentContextKey() { switch gui.currentContext().GetKey() {
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY: case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
return gui.getSideContextSelectedItemId() return gui.getSideContextSelectedItemId()
default: default:

View File

@ -234,7 +234,7 @@ func (gui *Gui) refreshMainViewForLineByLine() error {
var includedLineIndices []int var includedLineIndices []int
// I'd prefer not to have knowledge of contexts using this file but I'm not sure // I'd prefer not to have knowledge of contexts using this file but I'm not sure
// how to get around this // how to get around this
if gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey() { if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() {
filename := gui.getSelectedCommitFileName() filename := gui.getSelectedCommitFileName()
var err error var err error
includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename) includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename)