Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pkg/gui/controllers/filtering_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,29 @@ func (self *FilteringMenuAction) Call() error {
}

func (self *FilteringMenuAction) setFilteringPath(path string) error {
self.c.Modes().Filtering.Reset()
wasFiltering := self.c.Modes().Filtering.Active()
self.c.Modes().Filtering.SetAuthor("")
self.c.Modes().Filtering.SetPath(path)
return self.setFiltering()
return self.setFiltering(wasFiltering)
}

func (self *FilteringMenuAction) setFilteringAuthor(author string) error {
self.c.Modes().Filtering.Reset()
wasFiltering := self.c.Modes().Filtering.Active()
self.c.Modes().Filtering.SetPath("")
self.c.Modes().Filtering.SetAuthor(author)
return self.setFiltering()
return self.setFiltering(wasFiltering)
}

func (self *FilteringMenuAction) setFiltering() error {
func (self *FilteringMenuAction) setFiltering(wasFiltering bool) error {
self.c.Modes().Filtering.SetSelectedCommitHash(self.c.Contexts().LocalCommits.GetSelectedCommitHash())

repoState := self.c.State().GetRepoState()
if repoState.GetScreenMode() == types.SCREEN_NORMAL {
repoState.SetScreenMode(types.SCREEN_HALF)
if !wasFiltering {
screenModeChanged := repoState.GetScreenMode() == types.SCREEN_NORMAL
self.c.Modes().Filtering.SetScreenModeChanged(screenModeChanged)
if screenModeChanged {
repoState.SetScreenMode(types.SCREEN_HALF)
}
}

self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/helpers/mode_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func (self *ModeHelper) ExitFilterMode() error {

func (self *ModeHelper) ClearFiltering() error {
selectedCommitHash := self.c.Contexts().LocalCommits.GetSelectedCommitHash()
self.c.Modes().Filtering.Reset()
if self.c.State().GetRepoState().GetScreenMode() == types.SCREEN_HALF {
if self.c.Modes().Filtering.ScreenModeChanged() && self.c.State().GetRepoState().GetScreenMode() == types.SCREEN_HALF {
self.c.State().GetRepoState().SetScreenMode(types.SCREEN_NORMAL)
}
self.c.Modes().Filtering.Reset()

self.c.Refresh(types.RefreshOptions{
Scope: ScopesToRefreshWhenFilteringModeChanges(),
Expand Down
10 changes: 10 additions & 0 deletions pkg/gui/modes/filtering/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Filtering struct {
path string // the filename that gets passed to git log
author string // the author that gets passed to git log
selectedCommitHash string // the commit that was selected before we entered filtering mode
screenModeChanged bool // whether entering filtering mode changed screen mode from normal -> half
}

func New(path string, author string) Filtering {
Expand All @@ -17,6 +18,7 @@ func (m *Filtering) Active() bool {
func (m *Filtering) Reset() {
m.path = ""
m.author = ""
m.screenModeChanged = false
}

func (m *Filtering) SetPath(path string) {
Expand All @@ -42,3 +44,11 @@ func (m *Filtering) SetSelectedCommitHash(hash string) {
func (m *Filtering) GetSelectedCommitHash() string {
return m.selectedCommitHash
}

func (m *Filtering) SetScreenModeChanged(changed bool) {
m.screenModeChanged = changed
}

func (m *Filtering) ScreenModeChanged() bool {
return m.screenModeChanged
}
19 changes: 19 additions & 0 deletions pkg/gui/modes/filtering/filtering_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package filtering

import "testing"

func TestFilteringScreenModeChangedReset(t *testing.T) {
mode := New("", "")
mode.SetPath("foo")
mode.SetScreenModeChanged(true)

if !mode.ScreenModeChanged() {
t.Fatalf("expected screenModeChanged to be true")
}

mode.Reset()

if mode.ScreenModeChanged() {
t.Fatalf("expected screenModeChanged to be false after Reset")
}
}