This commit is contained in:
Jesse Duffield 2022-02-13 12:47:15 +11:00
parent 33a223e981
commit 55af07a1bb
4 changed files with 22 additions and 15 deletions

View file

@ -43,13 +43,12 @@ func (gui *Gui) currentContextKeyIgnoringPopups() types.ContextKey {
// use replaceContext when you don't want to return to the original context upon // use replaceContext when you don't want to return to the original context upon
// hitting escape: you want to go that context's parent instead. // hitting escape: you want to go that context's parent instead.
func (gui *Gui) replaceContext(c types.Context) error { func (gui *Gui) replaceContext(c types.Context) error {
gui.State.ContextManager.Lock()
defer gui.State.ContextManager.Unlock()
if !c.IsFocusable() { if !c.IsFocusable() {
return nil return nil
} }
gui.State.ContextManager.Lock()
if len(gui.State.ContextManager.ContextStack) == 0 { if len(gui.State.ContextManager.ContextStack) == 0 {
gui.State.ContextManager.ContextStack = []types.Context{c} gui.State.ContextManager.ContextStack = []types.Context{c}
} else { } else {
@ -57,6 +56,8 @@ func (gui *Gui) replaceContext(c types.Context) error {
gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack[0:len(gui.State.ContextManager.ContextStack)-1], c) gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack[0:len(gui.State.ContextManager.ContextStack)-1], c)
} }
defer gui.State.ContextManager.Unlock()
return gui.activateContext(c) return gui.activateContext(c)
} }

View file

@ -43,7 +43,7 @@ func (self *ListContextTrait) HandleFocus(opts ...types.OnFocusOpts) error {
func (self *ListContextTrait) HandleFocusLost() error { func (self *ListContextTrait) HandleFocusLost() error {
self.viewTrait.SetOriginX(0) self.viewTrait.SetOriginX(0)
return self.Context.HandleFocus() return self.Context.HandleFocusLost()
} }
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view

View file

@ -33,15 +33,19 @@ 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.currentContext().GetKey() { c := gui.currentSideContext()
case "":
if c.GetKey() == "" {
return nil return nil
case context.FILES_CONTEXT_KEY, context.SUBMODULES_CONTEXT_KEY: }
switch v := c.(type) {
case *context.WorkingTreeContext, *context.SubmodulesContext:
// TODO: should we just return nil here? // TODO: should we just return nil here?
return []string{""} return []string{""}
case context.COMMIT_FILES_CONTEXT_KEY: case *context.CommitFilesContext:
return []string{gui.State.Contexts.CommitFiles.GetRefName()} return []string{v.GetRefName()}
case context.LOCAL_BRANCHES_CONTEXT_KEY: case *context.BranchesContext:
// for our local branches we want to include both the branch and its upstream // for our local branches we want to include both the branch and its upstream
branch := gui.State.Contexts.Branches.GetSelected() branch := gui.State.Contexts.Branches.GetSelected()
if branch != nil { if branch != nil {
@ -52,13 +56,13 @@ func (gui *Gui) currentDiffTerminals() []string {
return names return names
} }
return nil return nil
default: case types.IListContext:
itemId := gui.getSideContextSelectedItemId() itemId := v.GetSelectedItemId()
if itemId == "" {
return nil
}
return []string{itemId} return []string{itemId}
} }
return nil
} }
func (gui *Gui) currentDiffTerminal() string { func (gui *Gui) currentDiffTerminal() string {

View file

@ -70,6 +70,7 @@ M file1
s := s s := s
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, utils.NewDummyLog(), true) viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, utils.NewDummyLog(), true)
viewModel.SetTree()
for _, path := range s.collapsedPaths { for _, path := range s.collapsedPaths {
viewModel.ToggleCollapsed(path) viewModel.ToggleCollapsed(path)
} }
@ -128,6 +129,7 @@ M file1
s := s s := s
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, utils.NewDummyLog(), true) viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, utils.NewDummyLog(), true)
viewModel.SetTree()
for _, path := range s.collapsedPaths { for _, path := range s.collapsedPaths {
viewModel.ToggleCollapsed(path) viewModel.ToggleCollapsed(path)
} }