diff options
author | Noah Too <krivahtoo@gmail.com> | 2022-10-17 19:39:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 12:39:53 -0400 |
commit | be452d4c9abf7891111138000fe7683f169d69a5 (patch) | |
tree | 75d9967795d601f7dc7eacd5e3dede155bd36d1f /src/commands | |
parent | 02c7e941566a2d828e77dd33a6dda74c8a0c42ef (diff) |
add `filter` command (#205)
* add `filter` command
* cargo fmt
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/escape.rs | 9 | ||||
-rw-r--r-- | src/commands/filter.rs | 16 | ||||
-rw-r--r-- | src/commands/mod.rs | 1 | ||||
-rw-r--r-- | src/commands/reload.rs | 6 |
4 files changed, 31 insertions, 1 deletions
diff --git a/src/commands/escape.rs b/src/commands/escape.rs index 1a507df..26b3da4 100644 --- a/src/commands/escape.rs +++ b/src/commands/escape.rs @@ -1,9 +1,16 @@ use crate::context::AppContext; use crate::error::JoshutoResult; +use super::reload; + pub fn escape(context: &mut AppContext) -> JoshutoResult { if let Some(curr_dir_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() { - curr_dir_list.visual_mode_cancel(); + if curr_dir_list.get_visual_mode_anchor_index().is_some() { + curr_dir_list.visual_mode_cancel(); + } else { + // reload to clear current filter + reload::reload_dirlist(context)?; + } }; Ok(()) } diff --git a/src/commands/filter.rs b/src/commands/filter.rs new file mode 100644 index 0000000..b87c901 --- /dev/null +++ b/src/commands/filter.rs @@ -0,0 +1,16 @@ +use crate::context::AppContext; +use crate::error::JoshutoResult; + +use super::reload; + +pub fn filter(context: &mut AppContext, arg: &str) -> JoshutoResult { + let curr_tab = context.tab_context_mut().curr_tab_mut(); + curr_tab.option_mut().set_filter_string(arg); + + if let Some(list) = curr_tab.curr_list_mut() { + list.depreciate(); + } + + reload::soft_reload_curr_tab(context)?; + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0bf83ae..c4f7531 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -5,6 +5,7 @@ pub mod cursor_move; pub mod delete_files; pub mod escape; pub mod file_ops; +pub mod filter; pub mod flat; pub mod line_nums; pub mod new_directory; diff --git a/src/commands/reload.rs b/src/commands/reload.rs index f7197c1..fe5b6b3 100644 --- a/src/commands/reload.rs +++ b/src/commands/reload.rs @@ -92,6 +92,12 @@ pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> { } pub fn reload_dirlist(context: &mut AppContext) -> JoshutoResult { + // clear filter on reload + context + .tab_context_mut() + .curr_tab_mut() + .option_mut() + .set_filter_string(""); reload(context, &context.tab_context_ref().curr_tab_id())?; Ok(()) } |