summaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorkraem2021-09-20 04:45:07 +0000
committerGitHub2021-09-20 04:45:07 +0000
commit4a003782a51a94259ef3b5ddfacb2a148c5056e7 (patch)
tree1a512225ca556532ea55e2d16f98f18b71130948 /helix-term
parente0e41f4f775db1210b5a8d5d224ac74c7756471c (diff)
enable smart case regex search by default (#761)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs12
-rw-r--r--helix-term/src/ui/mod.rs12
2 files changed, 21 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 703b92d1..d40bb9cf 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -5,7 +5,7 @@ use helix_core::{
match_brackets,
movement::{self, Direction},
object, pos_at_coords,
- regex::{self, Regex},
+ regex::{self, Regex, RegexBuilder},
register::Register,
search, selection, surround, textobject, LineEnding, Position, Range, Rope, RopeGraphemes,
RopeSlice, Selection, SmallVec, Tendril, Transaction,
@@ -1154,7 +1154,15 @@ fn search_next_impl(cx: &mut Context, extend: bool) {
if let Some(query) = registers.read('/') {
let query = query.last().unwrap();
let contents = doc.text().slice(..).to_string();
- if let Ok(regex) = Regex::new(query) {
+ let case_insensitive = if cx.editor.config.smart_case {
+ !query.chars().any(char::is_uppercase)
+ } else {
+ false
+ };
+ if let Ok(regex) = RegexBuilder::new(query)
+ .case_insensitive(case_insensitive)
+ .build()
+ {
search_impl(doc, view, &contents, &regex, extend);
} else {
// get around warning `mutable_borrow_reservation_conflict`
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 07eef352..f6536eb2 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -20,6 +20,7 @@ pub use spinner::{ProgressSpinners, Spinner};
pub use text::Text;
use helix_core::regex::Regex;
+use helix_core::regex::RegexBuilder;
use helix_view::{Document, Editor, View};
use std::path::PathBuf;
@@ -53,7 +54,16 @@ pub fn regex_prompt(
return;
}
- match Regex::new(input) {
+ let case_insensitive = if cx.editor.config.smart_case {
+ !input.chars().any(char::is_uppercase)
+ } else {
+ false
+ };
+
+ match RegexBuilder::new(input)
+ .case_insensitive(case_insensitive)
+ .build()
+ {
Ok(regex) => {
let (view, doc) = current!(cx.editor);