refactor: only apply pattern items if regex is enabled
This commit is contained in:
parent
aa07594057
commit
e53d9e3d01
1 changed files with 41 additions and 22 deletions
|
@ -1483,8 +1483,10 @@ impl BufferSearchBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determines which pattern items are present in the search query and
|
// Determines which pattern items are present in the search query and
|
||||||
// updates the search options accordingly.
|
// updates the search options accordingly, only if the regex search option
|
||||||
|
// is enabled.
|
||||||
fn apply_pattern_items(&mut self, cx: &mut Context<Self>) {
|
fn apply_pattern_items(&mut self, cx: &mut Context<Self>) {
|
||||||
|
if self.search_options.contains(SearchOptions::REGEX) {
|
||||||
// Start from the default search options to ensure that any search
|
// Start from the default search options to ensure that any search
|
||||||
// option that is not to be updated does not changed.
|
// option that is not to be updated does not changed.
|
||||||
// For example, if `\c` was present in the query and the case
|
// For example, if `\c` was present in the query and the case
|
||||||
|
@ -1503,6 +1505,7 @@ impl BufferSearchBar {
|
||||||
|
|
||||||
self.set_search_options(search_options, cx);
|
self.set_search_options(search_options, cx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn adjust_query_regex_language(&self, cx: &mut App) {
|
fn adjust_query_regex_language(&self, cx: &mut App) {
|
||||||
let enable = self.search_options.contains(SearchOptions::REGEX);
|
let enable = self.search_options.contains(SearchOptions::REGEX);
|
||||||
|
@ -2921,8 +2924,24 @@ mod tests {
|
||||||
search_bar.update_in(cx, |search_bar, _, _| {
|
search_bar.update_in(cx, |search_bar, _, _| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_bar.search_options,
|
search_bar.search_options,
|
||||||
SearchOptions::CASE_SENSITIVE,
|
SearchOptions::NONE,
|
||||||
"Should have case sensitivity enabled when \\C pattern item is present"
|
"Should not apply pattern items if regex not enabled"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.simulate_keystrokes("backspace backspace");
|
||||||
|
|
||||||
|
search_bar.update_in(cx, |search_bar, window, cx| {
|
||||||
|
search_bar.toggle_search_option(SearchOptions::REGEX, window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.simulate_input("\\C");
|
||||||
|
|
||||||
|
search_bar.update_in(cx, |search_bar, _, _| {
|
||||||
|
assert_eq!(
|
||||||
|
search_bar.search_options,
|
||||||
|
SearchOptions::REGEX | SearchOptions::CASE_SENSITIVE,
|
||||||
|
"Should have case sensitivity enabled when \\C pattern item is present and regex is enabled"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2933,14 +2952,14 @@ mod tests {
|
||||||
assert_eq!(search_bar.raw_query(cx), "test");
|
assert_eq!(search_bar.raw_query(cx), "test");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_bar.search_options,
|
search_bar.search_options,
|
||||||
SearchOptions::NONE,
|
SearchOptions::REGEX,
|
||||||
"Should have case sensitivity disable when \\C pattern item is removed"
|
"Should have case sensitivity disabled when \\C pattern item is removed"
|
||||||
);
|
);
|
||||||
|
|
||||||
search_bar.toggle_search_option(SearchOptions::CASE_SENSITIVE, window, cx);
|
search_bar.toggle_search_option(SearchOptions::CASE_SENSITIVE, window, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_bar.search_options,
|
search_bar.search_options,
|
||||||
SearchOptions::CASE_SENSITIVE,
|
SearchOptions::REGEX | SearchOptions::CASE_SENSITIVE,
|
||||||
"Should have case sensitivity enabled by default"
|
"Should have case sensitivity enabled by default"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -2952,7 +2971,7 @@ mod tests {
|
||||||
assert_eq!(search_bar.raw_query(cx), "test\\c");
|
assert_eq!(search_bar.raw_query(cx), "test\\c");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_bar.search_options,
|
search_bar.search_options,
|
||||||
SearchOptions::NONE,
|
SearchOptions::REGEX,
|
||||||
"Should have no case sensitivity enabled when \\c pattern item is present"
|
"Should have no case sensitivity enabled when \\c pattern item is present"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -2963,7 +2982,7 @@ mod tests {
|
||||||
assert_eq!(search_bar.raw_query(cx), "test");
|
assert_eq!(search_bar.raw_query(cx), "test");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_bar.search_options,
|
search_bar.search_options,
|
||||||
SearchOptions::CASE_SENSITIVE,
|
SearchOptions::REGEX | SearchOptions::CASE_SENSITIVE,
|
||||||
"Should have case sensitivity enabled when \\c pattern item is removed"
|
"Should have case sensitivity enabled when \\c pattern item is removed"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue