A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
The filter leaves extensions out with -ext:lnk (1068)
gelenmedyaa1ff46f46faf
diff --git a/crates/rf-core/src/namefilter.rs b/crates/rf-core/src/namefilter.rsindex ce2dbaab..534cee9a 100644--- a/crates/rf-core/src/namefilter.rs+++ b/crates/rf-core/src/namefilter.rs@@ -1,7 +1,8 @@//! What a search text asks of a file's name: a part of the name (or a `*`/`?` pattern), and, with `ext:`, its extension.//!//! `ext:pdf`, `ext:.pdf`, `ext:jpg,png` and `ext:jpg;png` name extensions; the words beside it are the name part as before-//! (`rapor ext:pdf,docx`). A text may hold several `ext:` words: their extensions add up. The filter of the open folder, the search+//! (`rapor ext:pdf,docx`). A text may hold several `ext:` words: their extensions add up. `-ext:lnk` leaves those extensions+//! out (issue 1068: the Desktop folder without its shortcuts); it goes with `ext:` and with a name part alike. The filter of the open folder, the search//! of the subfolders on the disk and the one in the name index all read a text through this, so the three agree. (`kind:video` is//! turned into such a list by the app before it gets here: which extensions a kind has is the app's table.)@@ -12,6 +13,8 @@ pub struct NameFilter {pub name: String,/// The extensions asked for, lower case, without the dot. Empty: any.pub exts: Vec<String>,+ /// The extensions left out (`-ext:` words), the same way.+ pub not_exts: Vec<String>,}/// Does `text` hold an `ext:` word? (The cheap question, asked before [`parse`] where every name of a folder is tested.)@@ -19,19 +22,25 @@ pub fn has_ext_word(text: &str) -> bool {text.split_whitespace().any(|w| ext_list(w).is_some())}-/// The list of an `ext:` word (`None` for any other word, and for `ext:` with nothing after it: that is a name being typed).-fn ext_list(word: &str) -> Option<&str> {+/// The list of an `ext:` word and whether it leaves them out (`-ext:`); `None` for any other word, and for `ext:` with nothing+/// after it: that is a name being typed.+fn ext_list(word: &str) -> Option<(bool, &str)> {+ let (out, word) = match word.strip_prefix('-') {+ Some(rest) => (true, rest),+ None => (false, word),+ };let head = word.get(..4)?;let rest = &word[4..];- (head.eq_ignore_ascii_case("ext:") && !rest.trim_matches(['.', ',', ';', '=']).is_empty()).then_some(rest)+ (head.eq_ignore_ascii_case("ext:") && !rest.trim_matches(['.', ',', ';', '=']).is_empty()).then_some((out, rest))}pub fn parse(text: &str) -> NameFilter {- let mut exts: Vec<String> = Vec::new();+ let (mut exts, mut not_exts): (Vec<String>, Vec<String>) = (Vec::new(), Vec::new());let mut name: Vec<&str> = Vec::new();for word in text.split_whitespace() {match ext_list(word) {- Some(list) => {+ Some((out, list)) => {+ let exts = if out { &mut not_exts } else { &mut exts };// ("ext:=pdf" too: Windows' own search writes its filters with "=")for e in list.trim_start_matches('=').split([',', ';']) {use unicode_normalization::UnicodeNormalization as _;@@ -44,27 +53,32 @@ pub fn parse(text: &str) -> NameFilter {None => name.push(word),}}- NameFilter { name: name.join(" "), exts }+ NameFilter { name: name.join(" "), exts, not_exts }}impl NameFilter {/// Is the extension of `name` one of those asked for (any, when none was)? A name with no extension, and one that is only an/// extension (`.gitignore`), has none.+ /// And not one of those left out.pub fn ext_ok(&self, name: &str) -> bool {- if self.exts.is_empty() {+ if self.exts.is_empty() && self.not_exts.is_empty() {return true;}- let Some((stem, ext)) = name.rsplit_once('.') else { return false };- if stem.is_empty() {- return false;- }+ let ext = match name.rsplit_once('.') {+ Some((stem, ext)) if !stem.is_empty() => ext,+ // no extension: not one asked for, and not one left out+ _ => return self.exts.is_empty(),+ };+ let lower = (!ext.is_ascii()).then(|| {+ use unicode_normalization::UnicodeNormalization as _;+ ext.nfc().flat_map(char::to_lowercase).collect::<String>()+ });// (an ASCII extension, nearly every one, is compared as it is, with nothing made for it: this runs for every name in the list)- if ext.is_ascii() {- return self.exts.iter().any(|e| e.eq_ignore_ascii_case(ext));- }- use unicode_normalization::UnicodeNormalization as _;- let ext_lower: String = ext.nfc().flat_map(char::to_lowercase).collect();- self.exts.iter().any(|e| *e == ext_lower)+ let one_of = |list: &[String]| match &lower {+ None => list.iter().any(|e| e.eq_ignore_ascii_case(ext)),+ Some(l) => list.iter().any(|e| e == l),+ };+ !one_of(&self.not_exts) && (self.exts.is_empty() || one_of(&self.exts))}}@@ -74,12 +88,12 @@ mod tests {#[test]fn ext_words_are_taken_out_of_the_text() {- assert_eq!(parse("rapor ext:pdf"), NameFilter { name: "rapor".into(), exts: vec!["pdf".into()] });- assert_eq!(parse("ext:.JPG,png;*.gif yaz tatili"), NameFilter { name: "yaz tatili".into(), exts: vec!["jpg".into(), "png".into(), "gif".into()] });+ assert_eq!(parse("rapor ext:pdf"), NameFilter { name: "rapor".into(), exts: vec!["pdf".into()], not_exts: vec![] });+ assert_eq!(parse("ext:.JPG,png;*.gif yaz tatili"), NameFilter { name: "yaz tatili".into(), exts: vec!["jpg".into(), "png".into(), "gif".into()], not_exts: vec![] });assert_eq!(parse("EXT:=mp4 ext:mov ext:mp4").exts, ["mp4", "mov"], "several words add up, each extension once");// nothing to take out- assert_eq!(parse(" my text.txt "), NameFilter { name: "my text.txt".into(), exts: vec![] });- assert_eq!(parse("ext:"), NameFilter { name: "ext:".into(), exts: vec![] }, "still being typed: a name");+ assert_eq!(parse(" my text.txt "), NameFilter { name: "my text.txt".into(), exts: vec![], not_exts: vec![] });+ assert_eq!(parse("ext:"), NameFilter { name: "ext:".into(), exts: vec![], not_exts: vec![] }, "still being typed: a name");assert_eq!(parse("next:pdf").exts, Vec::<String>::new());assert!(has_ext_word("a ext:pdf") && !has_ext_word("a.ext b") && !has_ext_word("ext:") && !has_ext_word("ext:."));}@@ -93,4 +107,18 @@ mod tests {let tr = parse("ext:İŞ");assert!(tr.ext_ok("a.i̇ş"));}++ /// Issue 1068: `-ext:lnk` shows the Desktop without its shortcuts.+ #[test]+ fn a_minus_ext_word_leaves_those_extensions_out() {+ let f = parse("-ext:lnk,url");+ assert_eq!(f, NameFilter { name: String::new(), exts: vec![], not_exts: vec!["lnk".into(), "url".into()] });+ assert!(has_ext_word("-ext:lnk") && !has_ext_word("-ext:") && !has_ext_word("-lnk"));+ assert!(!f.ext_ok("Chrome.LNK") && !f.ext_ok("site.url"));+ assert!(f.ext_ok("rapor.pdf") && f.ext_ok("README") && f.ext_ok(".lnk"), "anything else stays, a name with no extension too");+ // with a list asked for and a name part+ let g = parse("rapor ext:pdf,docx -ext:docx");+ assert_eq!(g.name, "rapor");+ assert!(g.ext_ok("a.pdf") && !g.ext_ok("a.docx") && !g.ext_ok("a.txt"));+ }}