Skip to content

Commit

Permalink
Add ignore_case option
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Mar 2, 2024
1 parent 85bad8e commit 86e7768
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down Expand Up @@ -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()),
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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),
}
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 86e7768

Please sign in to comment.