Skip to content

Commit

Permalink
Simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Feb 12, 2024
1 parent 79f63a9 commit b44452d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 66 deletions.
10 changes: 5 additions & 5 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
11 changes: 0 additions & 11 deletions yazi-config/src/which/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
4 changes: 1 addition & 3 deletions yazi-core/src/which/commands/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand Down
34 changes: 0 additions & 34 deletions yazi-core/src/which/config.rs

This file was deleted.

2 changes: 0 additions & 2 deletions yazi-core/src/which/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod commands;
mod config;
mod sorter;
mod which;

pub use config::*;
pub use sorter::*;
pub use which::*;
34 changes: 23 additions & 11 deletions yazi-core/src/which/which.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
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 {
pub(super) layer: Layer,
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;
Expand All @@ -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;
}
}

0 comments on commit b44452d

Please sign in to comment.