From 4d949d77de01401a1223937ef42cd4fa3732fca7 Mon Sep 17 00:00:00 2001 From: Yahya Badran Date: Mon, 2 Jun 2025 07:36:07 +0200 Subject: [PATCH 1/2] feat(config): add `search.ignore_case_unless_smart` config option Enables case-insensitive search unless overridden by `search.smart_case` behavior. --- helix-term/src/commands.rs | 6 +++++- helix-term/src/ui/mod.rs | 2 +- helix-view/src/editor.rs | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 604d69243..f747cd565 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2283,7 +2283,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() @@ -2455,6 +2455,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, @@ -2464,6 +2465,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"), @@ -2515,8 +2517,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) => { diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 106bfbfb8..e31769797 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -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() diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bc811b88b..d7ab5b17f 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -486,6 +486,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. @@ -1036,6 +1038,7 @@ impl Default for SearchConfig { Self { wrap_around: true, smart_case: true, + ignore_case_unless_smart: false, } } } From d9bec02ed05478f659fea127b80cbcec1f273d86 Mon Sep 17 00:00:00 2001 From: Yahya Badran Date: Mon, 2 Jun 2025 17:15:26 +0200 Subject: [PATCH 2/2] docs: add entry for `search.ignore-case-unless-smart` --- book/src/editor.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/editor.md b/book/src/editor.md index 00db71d27..7d41d53c7 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -279,6 +279,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