mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Allow navigating excluded directories when shown
This commit is contained in:
parent
0a286f6049
commit
147911a289
2 changed files with 49 additions and 1 deletions
|
|
@ -33,7 +33,7 @@ impl Actor for ExcludeAdd {
|
||||||
|
|
||||||
// Check if the current folder itself is matched by any of the patterns
|
// Check if the current folder itself is matched by any of the patterns
|
||||||
// If so, don't apply the filter - we're viewing inside a gitignored directory
|
// If so, don't apply the filter - we're viewing inside a gitignored directory
|
||||||
if let Some(_cwd_path) = cwd.as_path() {
|
if let Some(cwd_path) = cwd.as_path() {
|
||||||
// Build a quick GlobSet to test if current folder matches any pattern
|
// Build a quick GlobSet to test if current folder matches any pattern
|
||||||
let mut test_builder = GlobSetBuilder::new();
|
let mut test_builder = GlobSetBuilder::new();
|
||||||
for pattern in &opt.patterns {
|
for pattern in &opt.patterns {
|
||||||
|
|
@ -44,6 +44,33 @@ impl Actor for ExcludeAdd {
|
||||||
test_builder.add(glob);
|
test_builder.add(glob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if CWD matches any ignore pattern
|
||||||
|
if let Ok(test_set) = test_builder.build() {
|
||||||
|
// Test both absolute path and relative components
|
||||||
|
let mut matches_ignore = test_set.is_match(cwd_path);
|
||||||
|
|
||||||
|
// Also check path components for patterns like "target" matching
|
||||||
|
// "/path/to/target"
|
||||||
|
if !matches_ignore {
|
||||||
|
if let Some(components) = cwd_path.to_str() {
|
||||||
|
for (i, _) in components.match_indices('/').skip(1) {
|
||||||
|
if let Some(subpath) = components.get(i + 1..) {
|
||||||
|
if test_set.is_match(subpath) {
|
||||||
|
matches_ignore = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're inside an excluded directory, don't apply any filters
|
||||||
|
// This allows viewing the contents of gitignored directories
|
||||||
|
if matches_ignore {
|
||||||
|
succ!();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get existing patterns from config
|
// Get existing patterns from config
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,27 @@ impl Actor for Ignore {
|
||||||
|
|
||||||
let exclude_patterns = YAZI.files.excludes_for_context(&cwd_str);
|
let exclude_patterns = YAZI.files.excludes_for_context(&cwd_str);
|
||||||
|
|
||||||
|
// Check if we're inside an excluded directory
|
||||||
|
// If so, don't apply filters to allow viewing excluded directory contents
|
||||||
|
if let Some(cwd_path) = cwd.as_path() {
|
||||||
|
// Quick test: does the CWD match any exclude pattern?
|
||||||
|
for pattern in &exclude_patterns {
|
||||||
|
if pattern.starts_with('!') {
|
||||||
|
continue; // Skip negation patterns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple pattern matching for common cases like ".git", "target", etc.
|
||||||
|
if let Some(name) = cwd_path.file_name().and_then(|n| n.to_str()) {
|
||||||
|
// Remove glob wildcards for comparison
|
||||||
|
let clean_pattern = pattern.trim_end_matches("/**").trim_start_matches("**/");
|
||||||
|
if name == clean_pattern || pattern == name {
|
||||||
|
// We're inside an excluded directory, skip applying filters
|
||||||
|
succ!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create glob matcher function for compiled patterns
|
// Create glob matcher function for compiled patterns
|
||||||
let glob_matcher: Option<Arc<dyn Fn(&std::path::Path) -> Option<bool> + Send + Sync>> =
|
let glob_matcher: Option<Arc<dyn Fn(&std::path::Path) -> Option<bool> + Send + Sync>> =
|
||||||
if !exclude_patterns.is_empty() {
|
if !exclude_patterns.is_empty() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue