mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
simplify the code [no ci]
This commit is contained in:
parent
451f43fe15
commit
1e0a73c4a6
4 changed files with 16 additions and 17 deletions
|
|
@ -154,12 +154,11 @@ impl Executor {
|
|||
"find" => {
|
||||
let query = exec.args.get(0).map(|s| s.as_str());
|
||||
let prev = exec.named.contains_key("previous");
|
||||
let smart_case = exec.named.contains_key("smart-case");
|
||||
let ingore_case = exec.named.contains_key("ignore-case");
|
||||
let case = match (smart_case, ingore_case) {
|
||||
(false, false) => FinderCase::CaseSensitive,
|
||||
(false, true) => FinderCase::CaseInsensitive,
|
||||
(true, _) => FinderCase::SmartCase, // prioritize smart-case over ignore-case
|
||||
let case = match (exec.named.contains_key("smart"), exec.named.contains_key("insensitive"))
|
||||
{
|
||||
(false, false) => FinderCase::Sensitive,
|
||||
(false, true) => FinderCase::Insensitive,
|
||||
(true, _) => FinderCase::Smart, // prioritize smart over insensitive
|
||||
};
|
||||
cx.manager.active_mut().find(query, prev, case)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ keymap = [
|
|||
{ on = [ "c", "n" ], exec = "copy name_without_ext", desc = "Copy the name of the file without the extension" },
|
||||
|
||||
# Find
|
||||
{ on = [ "/" ], exec = "find --smart-case" },
|
||||
{ on = [ "?" ], exec = "find --previous --smart-case" },
|
||||
{ on = [ "/" ], exec = "find --smart" },
|
||||
{ on = [ "?" ], exec = "find --previous --smart" },
|
||||
{ on = [ "n" ], exec = "find_arrow" },
|
||||
{ on = [ "N" ], exec = "find_arrow --previous" },
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ use shared::Url;
|
|||
|
||||
use crate::files::Files;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum FinderCase {
|
||||
CaseSensitive,
|
||||
CaseInsensitive,
|
||||
SmartCase,
|
||||
Sensitive,
|
||||
Insensitive,
|
||||
Smart,
|
||||
}
|
||||
|
||||
pub struct Finder {
|
||||
|
|
@ -22,9 +22,9 @@ pub struct Finder {
|
|||
impl Finder {
|
||||
pub(super) fn new(s: &str, case: FinderCase) -> Result<Self> {
|
||||
let query = match case {
|
||||
FinderCase::CaseSensitive => Regex::new(s)?,
|
||||
FinderCase::CaseInsensitive => RegexBuilder::new(s).case_insensitive(true).build()?,
|
||||
FinderCase::SmartCase => {
|
||||
FinderCase::Sensitive => Regex::new(s)?,
|
||||
FinderCase::Insensitive => RegexBuilder::new(s).case_insensitive(true).build()?,
|
||||
FinderCase::Smart => {
|
||||
let uppercase = s.chars().any(|c| c.is_uppercase());
|
||||
RegexBuilder::new(s).case_insensitive(!uppercase).build()?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,8 +299,8 @@ impl Tab {
|
|||
emit!(Call(
|
||||
Exec::call("find", vec![s])
|
||||
.with_bool("previous", prev)
|
||||
.with_bool("smart-case", case == FinderCase::SmartCase)
|
||||
.with_bool("ignore-case", case == FinderCase::CaseInsensitive)
|
||||
.with_bool("smart", case == FinderCase::Smart)
|
||||
.with_bool("insensitive", case == FinderCase::Insensitive)
|
||||
.vec(),
|
||||
KeymapLayer::Manager
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue