From 99c9804edb11d972c8e2b9b8a87f9a8e859b2aa5 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 4 Sep 2023 02:02:21 +0800 Subject: [PATCH] .. --- config/src/keymap/exec.rs | 19 +++++++++++++++---- core/src/manager/finder.rs | 1 - core/src/manager/tab.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/config/src/keymap/exec.rs b/config/src/keymap/exec.rs index f946ae5df..207088a56 100644 --- a/config/src/keymap/exec.rs +++ b/config/src/keymap/exec.rs @@ -89,12 +89,23 @@ impl Exec { impl Exec { #[inline] - pub fn call(cwd: &str, args: Vec) -> Vec { - vec![Exec { cmd: cwd.to_owned(), args, named: Default::default() }] + pub fn call(cwd: &str, args: Vec) -> Self { + Exec { cmd: cwd.to_owned(), args, named: Default::default() } } #[inline] - pub fn call_named(cwd: &str, named: BTreeMap) -> Vec { - vec![Exec { cmd: cwd.to_owned(), args: Default::default(), named }] + pub fn call_named(cwd: &str, named: BTreeMap) -> Self { + Exec { cmd: cwd.to_owned(), args: Default::default(), named } + } + + #[inline] + pub fn vec(self) -> Vec { vec![self] } + + #[inline] + pub fn with_bool(mut self, name: &str, state: bool) -> Self { + if state { + self.named.insert(name.to_string(), "".to_string()); + } + self } } diff --git a/core/src/manager/finder.rs b/core/src/manager/finder.rs index cc47ec8cf..0ac90aea4 100644 --- a/core/src/manager/finder.rs +++ b/core/src/manager/finder.rs @@ -39,7 +39,6 @@ impl Finder { if self.version == files.version() { return false; } - self.matched.clear(); let mut i = 0u8; diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index facd9d65d..a21070c2f 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -232,6 +232,36 @@ impl Tab { false } + pub fn find(&mut self, query: Option<&str>, prev: bool) -> bool { + if let Some(query) = query { + self.finder = Finder::new(query).ok(); + return self.find_arrow(prev); + } + + tokio::spawn(async move { + if let Ok(s) = emit!(Input(InputOpt::top("Find:"))).await { + emit!(Call( + Exec::call("find", vec![s]).with_bool("previous", prev).vec(), + KeymapLayer::Manager + )); + } + }); + false + } + + pub fn find_arrow(&mut self, prev: bool) -> bool { + let Some(finder) = &mut self.finder else { + return false; + }; + + let mut b = finder.catchup(&self.current.files); + if let Some(step) = finder.arrow(&self.current.files, self.current.cursor(), prev) { + b |= self.arrow(step); + } + + b + } + pub fn search(&mut self, grep: bool) -> bool { if let Some(handle) = self.search.take() { handle.abort();