diff options
author | Canop <cano.petrole@gmail.com> | 2021-10-13 15:51:25 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-10-13 15:51:25 +0200 |
commit | 929f2daa1e3dd6093fde6d0477b92c8dc8ee4390 (patch) | |
tree | ad1e6cad7ab79e8b7f7e18f377452acd6a1e47ac | |
parent | f0f8d73a0ddc4a90b275595738670b6298125ff6 (diff) |
Improve decision regarding trimming the root
When the user doesn't want root trimming, we won't trim even
when a search is active.
Fix #434
New decision process:
1. we never want to trim the root if there's a sort
2. if the user don't want root trimming, we don't trim
3. if there's a pattern, we try to show at least root matches
4. in other cases, as the user wants trimming, we trim
-rw-r--r-- | src/tree_build/builder.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/tree_build/builder.rs b/src/tree_build/builder.rs index f5e8752..37e406b 100644 --- a/src/tree_build/builder.rs +++ b/src/tree_build/builder.rs @@ -87,8 +87,16 @@ impl<'c> TreeBuilder<'c> { None }; let root_id = BLine::from_root(&mut blines, path, root_ignore_chain, &options)?; - let trim_root = options.pattern.is_some() - || (options.trim_root && !options.sort.is_some()); + let trim_root = match (options.trim_root, options.pattern.is_some(), options.sort.is_some()) { + // we never want to trim the root if there's a sort + (_, _, true) => false, + // if the user don't want root trimming, we don't trim + (false, _, _) => false, + // if there's a pattern, we try to show at least root matches + (_, true, _) => false, + // in other cases, as the user wants trimming, we trim + _ => true, + }; Ok(TreeBuilder { options, targeted_size, |