diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/case_sensitivity.rs | 2 | ||||
-rw-r--r-- | src/commands/mod.rs | 1 | ||||
-rw-r--r-- | src/commands/search_regex.rs | 29 |
3 files changed, 32 insertions, 0 deletions
diff --git a/src/commands/case_sensitivity.rs b/src/commands/case_sensitivity.rs index c604b74..658c7fe 100644 --- a/src/commands/case_sensitivity.rs +++ b/src/commands/case_sensitivity.rs @@ -6,6 +6,7 @@ use crate::error::JoshutoResult; pub enum SetType { String, Glob, + Regex, Fzf, } @@ -19,6 +20,7 @@ pub fn set_case_sensitivity( match set_type { SetType::String => options.string_case_sensitivity = case_sensitivity, SetType::Glob => options.glob_case_sensitivity = case_sensitivity, + SetType::Regex => options.regex_case_sensitivity = case_sensitivity, SetType::Fzf => options.fzf_case_sensitivity = case_sensitivity, } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 4753380..dcf3946 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -22,6 +22,7 @@ pub mod rename_file; pub mod search; pub mod search_fzf; pub mod search_glob; +pub mod search_regex; pub mod search_string; pub mod select; pub mod set_mode; diff --git a/src/commands/search_regex.rs b/src/commands/search_regex.rs new file mode 100644 index 0000000..90cc8f3 --- /dev/null +++ b/src/commands/search_regex.rs @@ -0,0 +1,29 @@ +use crate::context::{AppContext, MatchContext}; +use crate::error::JoshutoResult; + +use super::cursor_move; +use super::search; + +pub fn search_regex(context: &mut AppContext, pattern: &str) -> JoshutoResult { + let case_sensitivity = context + .config_ref() + .search_options_ref() + .regex_case_sensitivity; + + let search_context = MatchContext::new_regex(pattern, case_sensitivity)?; + + let curr_tab = &context.tab_context_ref().curr_tab_ref(); + let index = curr_tab.curr_list_ref().and_then(|c| c.get_index()); + + let offset = match index { + Some(index) => index + 1, + None => return Ok(()), + }; + + if let Some(new_index) = search::search_next_impl(curr_tab, &search_context, offset) { + cursor_move::cursor_move(context, new_index); + } + + context.set_search_context(search_context); + Ok(()) +} |