1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

deal with the fact that a nil wrapped in an interface is not equal to nil

This commit is contained in:
Jesse Duffield
2020-08-22 15:56:30 +10:00
parent e290710f67
commit 5874529f43
6 changed files with 91 additions and 64 deletions

View File

@ -45,8 +45,6 @@ type Context interface {
GetWindowName() string
SetWindowName(string)
GetKey() string
GetSelectedItemId() string
GetSelectedItem() ListItem
SetParentContext(Context)
GetParentContext() Context
}
@ -64,10 +62,6 @@ func (c BasicContext) SetWindowName(windowName string) {
panic("can't set window name on basic context")
}
func (c BasicContext) GetSelectedItem() ListItem {
return nil
}
func (c BasicContext) GetWindowName() string {
// TODO: fix this up
return c.GetViewName()
@ -81,11 +75,6 @@ func (c BasicContext) GetParentContext() Context {
panic("can't get parent context on basic context")
}
// TODO: think about whether we need this on the Context interface or if it should just be on the ListContext struct
func (c BasicContext) GetSelectedItemId() string {
return ""
}
func (c BasicContext) HandleRender() error {
if c.OnRender != nil {
return c.OnRender()
@ -534,7 +523,12 @@ func (gui *Gui) currentSideContext() *ListContext {
context := stack[len(stack)-1-i]
if context.GetKind() == SIDE_CONTEXT {
return context.(*ListContext)
// not all side contexts are list contexts (e.g. the status panel)
listContext, ok := context.(*ListContext)
if !ok {
return nil
}
return listContext
}
}
@ -694,11 +688,17 @@ func (gui *Gui) getCurrentSideView() *gocui.View {
return view
}
func (gui *Gui) getSideContextSelectedItem() ListItem {
func (gui *Gui) getSideContextSelectedItemId() string {
currentSideContext := gui.currentSideContext()
if currentSideContext == nil {
return nil
return ""
}
return currentSideContext.GetSelectedItem()
item, ok := currentSideContext.GetSelectedItem()
if ok {
return item.ID()
}
return ""
}