Badran 2025-06-14 14:31:24 -07:00 committed by GitHub
commit 4413e51b0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 2 deletions

View File

@ -280,6 +280,7 @@ Search specific options.
| Key | Description | Default |
|--|--|---------|
| `smart-case` | Enable smart case regex searching (case-insensitive unless pattern contains upper case characters) | `true` |
| `ignore-case-unless-smart` | Enable case-insensitive search, unless overridden by `smart-case` behavior | `false` |
| `wrap-around`| Whether the search should wrap after depleting the matches | `true` |
### `[editor.whitespace]` Section

View File

@ -2285,7 +2285,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
let case_insensitive = if search_config.smart_case {
!query.chars().any(char::is_uppercase)
} else {
false
search_config.ignore_case_unless_smart
};
let wrap_around = search_config.wrap_around;
if let Ok(regex) = rope::RegexBuilder::new()
@ -2457,6 +2457,7 @@ fn global_search(cx: &mut Context) {
struct GlobalSearchConfig {
smart_case: bool,
ignore_case_unless_smart: bool,
file_picker_config: helix_view::editor::FilePickerConfig,
directory_style: Style,
number_style: Style,
@ -2466,6 +2467,7 @@ fn global_search(cx: &mut Context) {
let config = cx.editor.config();
let config = GlobalSearchConfig {
smart_case: config.search.smart_case,
ignore_case_unless_smart: config.search.ignore_case_unless_smart,
file_picker_config: config.file_picker.clone(),
directory_style: cx.editor.theme.get("ui.text.directory"),
number_style: cx.editor.theme.get("constant.numeric.integer"),
@ -2517,8 +2519,10 @@ fn global_search(cx: &mut Context) {
.map(|doc| (doc.path().cloned(), doc.text().to_owned()))
.collect();
let use_case_insensitive = !config.smart_case && config.ignore_case_unless_smart;
let matcher = match RegexMatcherBuilder::new()
.case_smart(config.smart_case)
.case_insensitive(use_case_insensitive)
.build(query)
{
Ok(matcher) => {

View File

@ -120,7 +120,7 @@ pub fn raw_regex_prompt(
let case_insensitive = if config.search.smart_case {
!input.chars().any(char::is_uppercase)
} else {
false
config.search.ignore_case_unless_smart
};
match rope::RegexBuilder::new()

View File

@ -490,6 +490,8 @@ impl Default for LspConfig {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct SearchConfig {
/// Enables case-insensitive search, unless overridden by `smart_case` behavior. Defaults to false.
pub ignore_case_unless_smart: bool,
/// Smart case: Case insensitive searching unless pattern contains upper case characters. Defaults to true.
pub smart_case: bool,
/// Whether the search should wrap after depleting the matches. Default to true.
@ -1040,6 +1042,7 @@ impl Default for SearchConfig {
Self {
wrap_around: true,
smart_case: true,
ignore_case_unless_smart: false,
}
}
}