Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Sep 9, 2023
1 parent ccafcdd commit 99c9804
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
19 changes: 15 additions & 4 deletions config/src/keymap/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,23 @@ impl Exec {

impl Exec {
#[inline]
pub fn call(cwd: &str, args: Vec<String>) -> Vec<Self> {
vec![Exec { cmd: cwd.to_owned(), args, named: Default::default() }]
pub fn call(cwd: &str, args: Vec<String>) -> Self {
Exec { cmd: cwd.to_owned(), args, named: Default::default() }
}

#[inline]
pub fn call_named(cwd: &str, named: BTreeMap<String, String>) -> Vec<Self> {
vec![Exec { cmd: cwd.to_owned(), args: Default::default(), named }]
pub fn call_named(cwd: &str, named: BTreeMap<String, String>) -> Self {
Exec { cmd: cwd.to_owned(), args: Default::default(), named }
}

#[inline]
pub fn vec(self) -> Vec<Self> { 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
}
}
1 change: 0 additions & 1 deletion core/src/manager/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl Finder {
if self.version == files.version() {
return false;
}

self.matched.clear();

let mut i = 0u8;
Expand Down
30 changes: 30 additions & 0 deletions core/src/manager/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 99c9804

Please sign in to comment.