Skip to content

Commit

Permalink
Add new filter to only show tracked files in Files panel
Browse files Browse the repository at this point in the history
This allows to hide all non-tracked files on large repos
  • Loading branch information
veremenko-y authored and jesseduffield committed Nov 12, 2024
1 parent b0a766c commit fdeaf9c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ func (self *FilesController) handleStatusFilterPressed() error {
},
Key: 'u',
},
{
Label: self.c.Tr.FilterTrackedFiles,
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayTracked)
},
Key: 't',
},
{
Label: self.c.Tr.ResetFilter,
OnPress: func() error {
Expand Down
3 changes: 3 additions & 0 deletions pkg/gui/filetree/file_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
DisplayAll FileTreeDisplayFilter = iota
DisplayStaged
DisplayUnstaged
DisplayTracked
// this shows files with merge conflicts
DisplayConflicted
)
Expand Down Expand Up @@ -82,6 +83,8 @@ func (self *FileTree) getFilesForDisplay() []*models.File {
return self.FilterFiles(func(file *models.File) bool { return file.HasStagedChanges })
case DisplayUnstaged:
return self.FilterFiles(func(file *models.File) bool { return file.HasUnstagedChanges })
case DisplayTracked:
return self.FilterFiles(func(file *models.File) bool { return file.Tracked })
case DisplayConflicted:
return self.FilterFiles(func(file *models.File) bool { return file.HasMergeConflicts })
default:
Expand Down
13 changes: 13 additions & 0 deletions pkg/gui/filetree/file_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func TestFilterAction(t *testing.T) {
{Name: "file1", ShortStatus: "M ", HasStagedChanges: true},
},
},
{
name: "filter files that are tracked",
filter: DisplayTracked,
files: []*models.File{
{Name: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true},
{Name: "dir2/file5", ShortStatus: "M ", Tracked: false},
{Name: "file1", ShortStatus: "M ", Tracked: true},
},
expected: []*models.File{
{Name: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true},
{Name: "file1", ShortStatus: "M ", Tracked: true},
},
},
{
name: "filter all files",
filter: DisplayAll,
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type TranslationSet struct {
AllFilesDiffCopiedToast string
FilterStagedFiles string
FilterUnstagedFiles string
FilterTrackedFiles string
ResetFilter string
MergeConflictsTitle string
Checkout string
Expand Down Expand Up @@ -1075,6 +1076,7 @@ func EnglishTranslationSet() *TranslationSet {
AllFilesDiffCopiedToast: "All files diff copied to clipboard",
FilterStagedFiles: "Show only staged files",
FilterUnstagedFiles: "Show only unstaged files",
FilterTrackedFiles: "Show only tracked files",
ResetFilter: "Reset filter",
NoChangedFiles: "No changed files",
SoftReset: "Soft reset",
Expand Down

0 comments on commit fdeaf9c

Please sign in to comment.