diff --git a/yazi-config/src/lib.rs b/yazi-config/src/lib.rs index 6ef59ed8..cf7826dc 100644 --- a/yazi-config/src/lib.rs +++ b/yazi-config/src/lib.rs @@ -17,8 +17,8 @@ mod priority; mod tasks; pub mod theme; mod validation; -mod xdg; pub mod which; +mod xdg; pub use layout::*; pub(crate) use pattern::*; @@ -65,5 +65,5 @@ pub fn init() { THEME.with(Default::default); INPUT.with(Default::default); SELECT.with(Default::default); - WHICH.with(Default::default); + WHICH.with(Default::default); } diff --git a/yazi-config/src/which/sorting.rs b/yazi-config/src/which/sorting.rs index d9a0566f..4ce103e4 100644 --- a/yazi-config/src/which/sorting.rs +++ b/yazi-config/src/which/sorting.rs @@ -8,37 +8,36 @@ use serde::{Deserialize, Serialize}; pub enum SortBy { #[default] None, - Key, - Desc, + Key, + Desc, } impl FromStr for SortBy { - type Err = anyhow::Error; + type Err = anyhow::Error; - fn from_str(s: &str) -> Result { - Ok(match s { - "none" => Self::None, - "key" => Self::Key, - "desc" => Self::Desc, - _ => bail!("Invalid sort option: {s}") - }) - } + fn from_str(s: &str) -> Result { + Ok(match s { + "none" => Self::None, + "key" => Self::Key, + "desc" => Self::Desc, + _ => bail!("Invalid sort option: {s}"), + }) + } } impl TryFrom for SortBy { - type Error = anyhow::Error; + type Error = anyhow::Error; - fn try_from(value: String) -> Result { - Self::from_str(&value) - } + fn try_from(value: String) -> Result { Self::from_str(&value) } } impl ToString for SortBy { - fn to_string(&self) -> String { - match self { - Self::None => "none", - Self::Key => "key", - Self::Desc => "desc", - }.to_string() - } + fn to_string(&self) -> String { + match self { + Self::None => "none", + Self::Key => "key", + Self::Desc => "desc", + } + .to_string() + } } diff --git a/yazi-core/src/which/commands/show.rs b/yazi-core/src/which/commands/show.rs index 092eb5d4..2afb6649 100644 --- a/yazi-core/src/which/commands/show.rs +++ b/yazi-core/src/which/commands/show.rs @@ -42,21 +42,21 @@ impl Which { render!(); } - pub fn show_with(&mut self, key: &Key, layer: Layer) { - self.layer = layer; - self.times = 1; - self.cands = KEYMAP - .get(layer) - .iter() - .filter(|c| c.on.len() > 1 && &c.on[0] == key) - .map(|c| c.into()) - .collect(); + pub fn show_with(&mut self, key: &Key, layer: Layer) { + self.layer = layer; + self.times = 1; + self.cands = KEYMAP + .get(layer) + .iter() + .filter(|c| c.on.len() > 1 && &c.on[0] == key) + .map(|c| c.into()) + .collect(); - // sort "which" - self.conf.sorter().sort(&mut self.cands); + // sort "which" + self.conf.sorter().sort(&mut self.cands); - self.visible = true; - self.silent = false; - render!(); - } + self.visible = true; + self.silent = false; + render!(); + } } diff --git a/yazi-core/src/which/config.rs b/yazi-core/src/which/config.rs index 986eb3a5..6471972e 100644 --- a/yazi-core/src/which/config.rs +++ b/yazi-core/src/which/config.rs @@ -22,20 +22,13 @@ impl Default for Config { } impl Config { - #[allow(unused)] - pub(super) fn patch(&mut self, f: F) -> bool { - let old = self.clone(); - f(self); - *self != old - } #[inline] pub(super) fn sorter(&self) -> WhichSorter { - WhichSorter { - by: self.sort_by, - sensitive: self.sort_sensitive, - reverse: self.sort_reverse, - } + WhichSorter { + by: self.sort_by, + sensitive: self.sort_sensitive, + reverse: self.sort_reverse, + } } } - diff --git a/yazi-core/src/which/mod.rs b/yazi-core/src/which/mod.rs index 824b99b8..76a9d453 100644 --- a/yazi-core/src/which/mod.rs +++ b/yazi-core/src/which/mod.rs @@ -1,8 +1,8 @@ mod commands; -mod which; mod config; mod sorter; +mod which; -pub use which::*; pub use config::*; pub use sorter::*; +pub use which::*; diff --git a/yazi-core/src/which/sorter.rs b/yazi-core/src/which/sorter.rs index d73d9f91..0fd92f16 100644 --- a/yazi-core/src/which/sorter.rs +++ b/yazi-core/src/which/sorter.rs @@ -1,4 +1,4 @@ -use yazi_config::{which::SortBy, keymap::ControlCow}; +use yazi_config::{keymap::ControlCow, which::SortBy}; use yazi_shared::natsort; #[derive(Clone, Copy, Default, PartialEq)] @@ -14,26 +14,25 @@ impl WhichSorter { return false; } - let by_alphabetical = |a: &str, b: &str| { - let ordering = natsort(a.as_bytes(), b.as_bytes(), !self.sensitive); - if self.reverse { ordering.reverse() } else { ordering } - }; + let by_alphabetical = |a: &str, b: &str| { + let ordering = natsort(a.as_bytes(), b.as_bytes(), !self.sensitive); + if self.reverse { ordering.reverse() } else { ordering } + }; - match self.by { - SortBy::None => return false, - SortBy::Key => items.sort_unstable_by(|a, b| { - let a = a.on.iter().map(|c| c.to_string()).collect::(); - let b = b.on.iter().map(|c| c.to_string()).collect::(); - by_alphabetical(&a, &b) - }), - SortBy::Desc => items.sort_unstable_by(|a, b| { - // what if description isn't present (need to check if it's mandatory or not) - // in case if it is not present, should I just panic ? - by_alphabetical(a.desc.as_ref().unwrap(), b.desc.as_ref().unwrap()) - }) - } + match self.by { + SortBy::None => return false, + SortBy::Key => items.sort_unstable_by(|a, b| { + let a = a.on.iter().map(|c| c.to_string()).collect::(); + let b = b.on.iter().map(|c| c.to_string()).collect::(); + by_alphabetical(&a, &b) + }), + SortBy::Desc => items.sort_unstable_by(|a, b| { + // what if description isn't present (need to check if it's mandatory or not) + // in case if it is not present, should I just panic ? + by_alphabetical(a.desc.as_ref().unwrap(), b.desc.as_ref().unwrap()) + }), + } true } - } diff --git a/yazi-core/src/which/which.rs b/yazi-core/src/which/which.rs index b5e69aaa..fc8110ef 100644 --- a/yazi-core/src/which/which.rs +++ b/yazi-core/src/which/which.rs @@ -9,7 +9,7 @@ pub struct Which { pub times: usize, pub cands: Vec, - pub conf: Config, + pub conf: Config, pub visible: bool, pub silent: bool,