mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
79f63a9ae2
commit
b44452dbd9
6 changed files with 29 additions and 66 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -30,14 +30,3 @@ impl TryFrom<String> for SortBy {
|
|||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> { 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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
mod commands;
|
||||
mod config;
|
||||
mod sorter;
|
||||
mod which;
|
||||
|
||||
pub use config::*;
|
||||
pub use sorter::*;
|
||||
pub use which::*;
|
||||
|
|
|
|||
|
|
@ -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<ControlCow>,
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue