mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
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
This commit is contained in:
@ -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("")
|
||||
}
|
||||
|
@ -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("")
|
||||
}
|
||||
|
@ -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},
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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'"))
|
||||
|
@ -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().
|
||||
|
Reference in New Issue
Block a user