Skip to content

Commit

Permalink
strings: Add exact match and case sensitivity filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Mar 24, 2024
1 parent 275decc commit 3f4280a
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/gui/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct StringsView {
selected_string: u32,
string_selected_entries: Vec<(TagHash, String, TagType)>,
string_filter: String,

exact_match: bool,
case_sensitive: bool,
}

impl StringsView {
Expand All @@ -42,6 +45,8 @@ impl StringsView {
selected_string: u32::MAX,
string_filter: String::new(),
string_selected_entries: vec![],
exact_match: false,
case_sensitive: false,
}
}
}
Expand All @@ -64,14 +69,36 @@ impl View for StringsView {
ui.style_mut().wrap = Some(false);
ui.horizontal(|ui| {
ui.label("Search:");
if ui.text_edit_singleline(&mut self.string_filter).changed() {
let mut update_search =
ui.text_edit_singleline(&mut self.string_filter).changed();
update_search |= ui.checkbox(&mut self.exact_match, "Exact match").changed();
update_search |= ui
.checkbox(&mut self.case_sensitive, "Case sensitive")
.changed();

if update_search {
self.strings_vec_filtered = if !self.string_filter.is_empty() {
let match_b = if self.case_sensitive {
self.string_filter.clone()
} else {
self.string_filter.to_lowercase()
};

self.strings
.iter()
.filter(|(_, s)| {
s.iter().any(|s| {
s.to_lowercase()
.contains(&self.string_filter.to_lowercase())
let match_a = if self.case_sensitive {
s.clone()
} else {
s.to_lowercase()
};

if self.exact_match {
match_a == match_b
} else {
match_a.contains(&match_b)
}
})
})
.map(|(k, v)| (*k, v.clone()))
Expand Down

0 comments on commit 3f4280a

Please sign in to comment.