Skip to content

Commit fbe99fe

Browse files
committed
code_review: PR #2778
- Check `FilterType` instead of `FilterMode` since we have already checked the `_histroryFilterMode`. - Simplify `IsCoveredByFolderFilter` Signed-off-by: leo <longshuang@msn.cn>
1 parent a92f7bc commit fbe99fe

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

‎src/Models/RepositoryUIStates.cs‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,12 @@ public bool UpdateHistoryFilters(string pattern, FilterType type, FilterMode mod
357357
return true;
358358
}
359359

360-
public bool IsCoveredByFolderFilter(string path, FilterMode mode)
360+
public bool IsCoveredByFolderFilter(string path, FilterType type)
361361
{
362-
var idx = path.LastIndexOf('/');
363-
while (idx > 0)
362+
foreach (var filter in HistoryFilters)
364363
{
365-
var parent = path.Substring(0, idx);
366-
foreach (var filter in HistoryFilters)
367-
{
368-
if (filter.Type is FilterType.LocalBranchFolder or FilterType.RemoteBranchFolder &&
369-
filter.Mode == mode &&
370-
filter.Pattern.Equals(parent, StringComparison.Ordinal))
371-
return true;
372-
}
373-
374-
idx = parent.LastIndexOf('/');
364+
if (filter.Type == type && path.StartsWith($"{filter.Pattern}/", StringComparison.Ordinal))
365+
return true;
375366
}
376367

377368
return false;

‎src/ViewModels/Repository.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ public void RefreshAfterCreateBranch(Models.Branch created, bool checkout)
775775
_uiStates.ExpandedBranchNodesInSideBar.Add(created.FullName.Substring(0, folderEndIdx));
776776

777777
if (_historyFilterMode == Models.FilterMode.Included &&
778-
!_uiStates.IsCoveredByFolderFilter(created.FullName, Models.FilterMode.Included))
778+
!_uiStates.IsCoveredByFolderFilter(created.FullName, Models.FilterType.LocalBranchFolder))
779779
SetBranchFilterMode(created, Models.FilterMode.Included, false, false);
780780

781781
CurrentBranch = created;
@@ -819,7 +819,7 @@ public void RefreshAfterCheckoutBranch(Models.Branch checkouted)
819819
checkouted.IsCurrent = true;
820820
checkouted.WorktreePath = FullPath;
821821
if (_historyFilterMode == Models.FilterMode.Included &&
822-
!_uiStates.IsCoveredByFolderFilter(checkouted.FullName, Models.FilterMode.Included))
822+
!_uiStates.IsCoveredByFolderFilter(checkouted.FullName, Models.FilterType.LocalBranchFolder))
823823
SetBranchFilterMode(checkouted, Models.FilterMode.Included, false, false);
824824

825825
List<Models.Branch> locals = [];

0 commit comments

Comments
 (0)