summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyohei Uto <im@kyoheiu.dev>2024-03-02 14:52:48 +0900
committerKyohei Uto <im@kyoheiu.dev>2024-03-02 14:52:48 +0900
commit86e77688b2e75fd1abc3c683bbf9e96794fdd367 (patch)
tree3fd0d728e91d47730d611a7a6c6ed34497a3257b
parent85bad8e5b91cdc1b81397ec7fea63bd295a08ce2 (diff)
Add ignore_case optionfeature/case-insensitive-search
-rw-r--r--src/config.rs2
-rw-r--r--src/run.rs17
-rw-r--r--src/state.rs15
3 files changed, 27 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs
index ca20ffd..9ad2918 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -20,6 +20,7 @@ pub struct Config {
pub default: Option<String>,
pub match_vim_exit_behavior: Option<bool>,
pub exec: Option<BTreeMap<String, Vec<String>>>,
+ pub ignore_case: Option<bool>,
pub color: Option<ConfigColor>,
}
@@ -70,6 +71,7 @@ impl Default for Config {
default: Default::default(),
match_vim_exit_behavior: Default::default(),
exec: Default::default(),
+ ignore_case: Some(false),
color: Some(Default::default()),
}
}
diff --git a/src/run.rs b/src/run.rs
index 9a1ce8d..af0ca18 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1520,11 +1520,18 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let key = &keyword.iter().collect::<String>();
- let target = state
- .list
- .iter()
- .position(|x| x.file_name.contains(key));
-
+ let target = match state.ignore_case {
+ Some(true) => {
+ state.list.iter().position(|x| {
+ x.file_name
+ .to_lowercase()
+ .contains(&key.to_lowercase())
+ })
+ }
+ _ => state.list.iter().position(|x| {
+ x.file_name.contains(key)
+ }),
+ };
match target {
Some(i) => {
state.layout.nums.skip = i as u16;
diff --git a/src/state.rs b/src/state.rs
index 6b0ec76..3a4c6c6 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -52,6 +52,7 @@ pub struct State {
pub has_zoxide: bool,
pub default: String,
pub commands: Option<BTreeMap<String, String>>,
+ pub ignore_case: Option<bool>,
pub registers: Registers,
pub operations: Operation,
pub jumplist: JumpList,
@@ -263,6 +264,7 @@ impl State {
.unwrap_or_else(|| env::var("EDITOR").unwrap_or_default());
self.match_vim_exit_behavior = config.match_vim_exit_behavior.unwrap_or_default();
self.commands = to_extension_map(&config.exec);
+ self.ignore_case = config.ignore_case;
let colors = config.color.unwrap_or_default();
self.layout.colors = colors;
}
@@ -1285,7 +1287,13 @@ impl State {
/// Highlight matched items.
pub fn highlight_matches(&mut self, keyword: &str) {
for item in self.list.iter_mut() {
- item.matches = item.file_name.contains(keyword);
+ item.matches = match self.ignore_case {
+ Some(true) => item
+ .file_name
+ .to_lowercase()
+ .contains(&keyword.to_lowercase()),
+ _ => item.file_name.contains(keyword),
+ }
}
}
@@ -1599,7 +1607,10 @@ impl State {
let count = self
.list
.iter()
- .filter(|x| x.file_name.contains(keyword))
+ .filter(|x| match self.ignore_case {
+ Some(true) => x.file_name.to_lowercase().contains(&keyword.to_lowercase()),
+ _ => x.file_name.contains(keyword),
+ })
.count();
let count = if count <= 1 {
format!("{} match", count)