From fdeaf9cea0cbd71f3ed8dbf9a369f78f02d0a3a6 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Fri, 1 Nov 2024 16:21:09 -0600 Subject: [PATCH] Add new filter to only show tracked files in Files panel This allows to hide all non-tracked files on large repos --- pkg/gui/controllers/files_controller.go | 7 +++++++ pkg/gui/filetree/file_tree.go | 3 +++ pkg/gui/filetree/file_tree_test.go | 13 +++++++++++++ pkg/i18n/english.go | 2 ++ 4 files changed, 25 insertions(+) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 5380c890975..1ea20eeb218 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -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 { diff --git a/pkg/gui/filetree/file_tree.go b/pkg/gui/filetree/file_tree.go index f2108ab28a9..12780e3ed3d 100644 --- a/pkg/gui/filetree/file_tree.go +++ b/pkg/gui/filetree/file_tree.go @@ -15,6 +15,7 @@ const ( DisplayAll FileTreeDisplayFilter = iota DisplayStaged DisplayUnstaged + DisplayTracked // this shows files with merge conflicts DisplayConflicted ) @@ -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: diff --git a/pkg/gui/filetree/file_tree_test.go b/pkg/gui/filetree/file_tree_test.go index 856d25f9a98..a3cdfd96665 100644 --- a/pkg/gui/filetree/file_tree_test.go +++ b/pkg/gui/filetree/file_tree_test.go @@ -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, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index e141a614ccb..fa28130a94a 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -87,6 +87,7 @@ type TranslationSet struct { AllFilesDiffCopiedToast string FilterStagedFiles string FilterUnstagedFiles string + FilterTrackedFiles string ResetFilter string MergeConflictsTitle string Checkout string @@ -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",