summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-06-26 11:15:47 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-03 12:54:14 +1000
commit8e46b8a275587ef442cca8497d9c5056556bfa93 (patch)
tree11e170257c4e33d7c9918e9729a52c0cfc606f6e
parentcd989d8ebeb923af74e8074cee09863b50862410 (diff)
Use searching, not filtering, in file tree views
There's more work to be done to support filtering for these views so we're sticking with searching for now
-rw-r--r--pkg/gui/context/commit_files_context.go34
-rw-r--r--pkg/gui/context/working_tree_context.go39
-rw-r--r--pkg/gui/controllers/switch_to_diff_files_controller.go2
-rw-r--r--pkg/integration/tests/filter_and_search/filter_commit_files.go2
-rw-r--r--pkg/integration/tests/filter_and_search/filter_files.go2
-rw-r--r--pkg/integration/tests/filter_and_search/nested_filter.go4
-rw-r--r--pkg/integration/tests/filter_and_search/nested_filter_transient.go5
7 files changed, 33 insertions, 55 deletions
diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go
index 54d2a02e3..5cb11d9cc 100644
--- a/pkg/gui/context/commit_files_context.go
+++ b/pkg/gui/context/commit_files_context.go
@@ -10,10 +10,10 @@ import (
)
type CommitFilesContext struct {
- *FilteredList[*models.CommitFile]
*filetree.CommitFileTreeViewModel
*ListContextTrait
*DynamicTitleBuilder
+ *SearchTrait
}
var (
@@ -22,13 +22,8 @@ var (
)
func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
- filteredList := NewFilteredList(
- func() []*models.CommitFile { return c.Model().CommitFiles },
- func(file *models.CommitFile) []string { return []string{file.GetPath()} },
- )
-
viewModel := filetree.NewCommitFileTreeViewModel(
- func() []*models.CommitFile { return filteredList.GetFilteredList() },
+ func() []*models.CommitFile { return c.Model().CommitFiles },
c.Log,
c.UserConfig.Gui.ShowFileTree,
)
@@ -44,10 +39,10 @@ func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
})
}
- return &CommitFilesContext{
- FilteredList: filteredList,
+ ctx := &CommitFilesContext{
CommitFileTreeViewModel: viewModel,
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.CommitFilesDynamicTitle),
+ SearchTrait: NewSearchTrait(c),
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
@@ -64,6 +59,13 @@ func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
c: c,
},
}
+
+ ctx.GetView().SetOnSelectItem(ctx.SearchTrait.onSelectItemWrapper(func(selectedLineIdx int) error {
+ ctx.GetList().SetSelectedLineIdx(selectedLineIdx)
+ return ctx.HandleFocus(types.OnFocusOpts{})
+ }))
+
+ return ctx
}
func (self *CommitFilesContext) GetSelectedItemId() string {
@@ -78,17 +80,3 @@ func (self *CommitFilesContext) GetSelectedItemId() string {
func (self *CommitFilesContext) GetDiffTerminals() []string {
return []string{self.GetRef().RefName()}
}
-
-// used for type switch
-func (self *CommitFilesContext) IsFilterableContext() {}
-
-// TODO: see if we can just call SetTree() within HandleRender(). It doesn't seem
-// right that we need to imperatively refresh the view model like this
-func (self *CommitFilesContext) SetFilter(filter string) {
- self.FilteredList.SetFilter(filter)
- self.SetTree()
-}
-
-func (self *CommitFilesContext) ClearFilter() {
- self.SetFilter("")
-}
diff --git a/pkg/gui/context/working_tree_context.go b/pkg/gui/context/working_tree_context.go
index ee053eea1..107228ee8 100644
--- a/pkg/gui/context/working_tree_context.go
+++ b/pkg/gui/context/working_tree_context.go
@@ -9,24 +9,16 @@ import (
)
type WorkingTreeContext struct {
- *FilteredList[*models.File]
*filetree.FileTreeViewModel
*ListContextTrait
+ *SearchTrait
}
-var (
- _ types.IListContext = (*WorkingTreeContext)(nil)
- _ types.IFilterableContext = (*WorkingTreeContext)(nil)
-)
+var _ types.IListContext = (*WorkingTreeContext)(nil)
func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
- filteredList := NewFilteredList(
- func() []*models.File { return c.Model().Files },
- func(file *models.File) []string { return []string{file.GetPath()} },
- )
-
viewModel := filetree.NewFileTreeViewModel(
- func() []*models.File { return filteredList.GetFilteredList() },
+ func() []*models.File { return c.Model().Files },
c.Log,
c.UserConfig.Gui.ShowFileTree,
)
@@ -38,8 +30,8 @@ func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
})
}
- return &WorkingTreeContext{
- FilteredList: filteredList,
+ ctx := &WorkingTreeContext{
+ SearchTrait: NewSearchTrait(c),
FileTreeViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
@@ -54,6 +46,13 @@ func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
c: c,
},
}
+
+ ctx.GetView().SetOnSelectItem(ctx.SearchTrait.onSelectItemWrapper(func(selectedLineIdx int) error {
+ ctx.GetList().SetSelectedLineIdx(selectedLineIdx)
+ return ctx.HandleFocus(types.OnFocusOpts{})
+ }))
+
+ return ctx
}
func (self *WorkingTreeContext) GetSelectedItemId() string {
@@ -64,17 +63,3 @@ func (self *WorkingTreeContext) GetSelectedItemId() string {
return item.ID()
}
-
-// used for type switch
-func (self *WorkingTreeContext) IsFilterableContext() {}
-
-// TODO: see if we can just call SetTree() within HandleRender(). It doesn't seem
-// right that we need to imperatively refresh the view model like this
-func (self *WorkingTreeContext) SetFilter(filter string) {
- self.FilteredList.SetFilter(filter)
- self.SetTree()
-}
-
-func (self *WorkingTreeContext) ClearFilter() {
- self.SetFilter("")
-}
diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go
index 767520d20..971efb7a1 100644
--- a/pkg/gui/controllers/switch_to_diff_files_controller.go
+++ b/pkg/gui/controllers/switch_to_diff_files_controller.go
@@ -83,7 +83,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte
diffFilesContext.SetCanRebase(opts.CanRebase)
diffFilesContext.SetParentContext(opts.Context)
diffFilesContext.SetWindowName(opts.Context.GetWindowName())
- diffFilesContext.ClearFilter()
+ diffFilesContext.ClearSearchString()
if err := self.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.COMMIT_FILES},
diff --git a/pkg/integration/tests/filter_and_search/filter_commit_files.go b/pkg/integration/tests/filter_and_search/filter_commit_files.go
index a1a39f1f4..953eaf34d 100644
--- a/pkg/integration/tests/filter_and_search/filter_commit_files.go
+++ b/pkg/integration/tests/filter_and_search/filter_commit_files.go
@@ -8,7 +8,7 @@ import (
var FilterCommitFiles = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Basic commit file filtering by text",
ExtraCmdArgs: []string{},
- Skip: false,
+ Skip: true, // skipping until we have implemented file view filtering
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateDir("folder1")
diff --git a/pkg/integration/tests/filter_and_search/filter_files.go b/pkg/integration/tests/filter_and_search/filter_files.go
index 5a029b146..6eae90c18 100644
--- a/pkg/integration/tests/filter_and_search/filter_files.go
+++ b/pkg/integration/tests/filter_and_search/filter_files.go
@@ -8,7 +8,7 @@ import (
var FilterFiles = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Basic file filtering by text",
ExtraCmdArgs: []string{},
- Skip: false,
+ Skip: true, // Skipping until we have implemented file view filtering
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateDir("folder1")
diff --git a/pkg/integration/tests/filter_and_search/nested_filter.go b/pkg/integration/tests/filter_and_search/nested_filter.go
index 7dad9d61a..6444ad523 100644
--- a/pkg/integration/tests/filter_and_search/nested_filter.go
+++ b/pkg/integration/tests/filter_and_search/nested_filter.go
@@ -67,7 +67,9 @@ var NestedFilter = NewIntegrationTest(NewIntegrationTestArgs{
).
FilterOrSearch("grape").
Lines(
+ Contains(`apple`),
Contains(`grape`).IsSelected(),
+ Contains(`orange`),
).
PressEnter()
@@ -85,7 +87,9 @@ var NestedFilter = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().CommitFiles().
IsFocused().
Lines(
+ Contains(`apple`),
Contains(`grape`).IsSelected(),
+ Contains(`orange`),
).
Tap(func() {
t.Views().Search().IsVisible().Content(Contains("matches for 'grape'"))
diff --git a/pkg/integration/tests/filter_and_search/nested_filter_transient.go b/pkg/integration/tests/filter_and_search/nested_filter_transient.go
index 300519784..bf04406f5 100644
--- a/pkg/integration/tests/filter_and_search/nested_filter_transient.go
+++ b/pkg/integration/tests/filter_and_search/nested_filter_transient.go
@@ -72,9 +72,10 @@ var NestedFilterTransient = NewIntegrationTest(NewIntegrationTestArgs{
Contains(`file-one`).IsSelected(),
Contains(`file-two`),
).
- FilterOrSearch("one").
+ FilterOrSearch("two").
Lines(
- Contains(`file-one`).IsSelected(),
+ Contains(`file-one`),
+ Contains(`file-two`).IsSelected(),
)
t.Views().Branches().