diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 53005265..82c4cdde 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -2,11 +2,6 @@ # If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas. "$schema" = "https://yazi-rs.github.io/schemas/yazi.json" -[which] -sort_by = "none" -sort_sensitive = false -sort_reverse = false - [manager] ratio = [ 1, 4, 3 ] sort_by = "alphabetical" @@ -188,5 +183,10 @@ open_title = "Open with:" open_origin = "hovered" open_offset = [ 0, 1, 50, 7 ] +[which] +sort_by = "none" +sort_sensitive = false +sort_reverse = false + [log] enabled = false diff --git a/yazi-config/src/which/sorting.rs b/yazi-config/src/which/sorting.rs index 4ce103e4..cb38e803 100644 --- a/yazi-config/src/which/sorting.rs +++ b/yazi-config/src/which/sorting.rs @@ -30,14 +30,3 @@ impl TryFrom for SortBy { 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() - } -} diff --git a/yazi-core/src/which/commands/show.rs b/yazi-core/src/which/commands/show.rs index 2afb6649..4794e6ec 100644 --- a/yazi-core/src/which/commands/show.rs +++ b/yazi-core/src/which/commands/show.rs @@ -52,9 +52,7 @@ impl Which { .map(|c| c.into()) .collect(); - // sort "which" - self.conf.sorter().sort(&mut self.cands); - + self.sorter().sort(&mut self.cands); self.visible = true; self.silent = false; render!(); diff --git a/yazi-core/src/which/config.rs b/yazi-core/src/which/config.rs deleted file mode 100644 index 6471972e..00000000 --- a/yazi-core/src/which/config.rs +++ /dev/null @@ -1,34 +0,0 @@ -use yazi_config::{which::SortBy, WHICH}; - -use crate::which::WhichSorter; - -#[derive(Clone, PartialEq, Debug)] -pub struct Config { - // Sorting - pub sort_by: SortBy, - pub sort_sensitive: bool, - pub sort_reverse: bool, -} - -impl Default for Config { - fn default() -> Self { - Self { - // Sorting - sort_by: WHICH.sort_by, - sort_sensitive: WHICH.sort_sensitive, - sort_reverse: WHICH.sort_reverse, - } - } -} - -impl Config { - - #[inline] - pub(super) fn sorter(&self) -> WhichSorter { - 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 76a9d453..ebc217a8 100644 --- a/yazi-core/src/which/mod.rs +++ b/yazi-core/src/which/mod.rs @@ -1,8 +1,6 @@ mod commands; -mod config; mod sorter; mod which; -pub use config::*; pub use sorter::*; pub use which::*; diff --git a/yazi-core/src/which/which.rs b/yazi-core/src/which/which.rs index fc8110ef..3b34d6f5 100644 --- a/yazi-core/src/which/which.rs +++ b/yazi-core/src/which/which.rs @@ -1,7 +1,7 @@ -use yazi_config::keymap::{ControlCow, Key}; +use yazi_config::{keymap::{ControlCow, Key}, which::SortBy}; use yazi_shared::{emit, render, Layer}; -use crate::which::Config; +use super::WhichSorter; #[derive(Default, Debug)] pub struct Which { @@ -9,21 +9,17 @@ pub struct Which { pub times: usize, pub cands: Vec, - pub conf: Config, + // Sorting + sort_by: SortBy, + sort_sensitive: bool, + sort_reverse: bool, + // Visibility pub visible: bool, pub silent: bool, } impl Which { - fn reset(&mut self) { - self.times = 0; - self.cands.clear(); - - self.visible = false; - self.silent = false; - } - pub fn type_(&mut self, key: Key) -> bool { self.cands.retain(|c| c.on.len() > self.times && c.on[self.times] == key); self.times += 1; @@ -41,4 +37,20 @@ impl Which { render!(); true } + + pub(super) fn sorter(&self) -> WhichSorter { + WhichSorter { + by: self.sort_by, + sensitive: self.sort_sensitive, + reverse: self.sort_reverse, + } + } + + fn reset(&mut self) { + self.times = 0; + self.cands.clear(); + + self.visible = false; + self.silent = false; + } }