Skip to content

Commit

Permalink
helix-term: enable smartcase search by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kraem committed Sep 15, 2021
1 parent ef532e0 commit e852678
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1154,7 +1154,8 @@ 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();
let regex = Regex::new(query).unwrap();
let case_insensitive = if cx.editor.config.smartcase { query.to_owned() == query.to_lowercase() } else { false };
let regex = RegexBuilder::new(query).case_insensitive(case_insensitive).build().expect("unable to build regex");
search_impl(doc, view, &contents, &regex, extend);
}
}
Expand Down
5 changes: 4 additions & 1 deletion helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +54,9 @@ pub fn regex_prompt(
return;
}

match Regex::new(input) {
let case_insensitive = if cx.editor.config.smartcase { input == input.to_lowercase() } else { false };

match RegexBuilder::new(input).case_insensitive(case_insensitive).build() {
Ok(regex) => {
let (view, doc) = current!(cx.editor);

Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct Config {
pub line_number: LineNumber,
/// Middle click paste support. Defaults to true
pub middle_click_paste: bool,
/// Smartcase: Case insensitive searching unless pattern has upper case character
pub smartcase: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
Expand All @@ -64,6 +66,7 @@ impl Default for Config {
},
line_number: LineNumber::Absolute,
middle_click_paste: true,
smartcase: true,
}
}
}
Expand Down

0 comments on commit e852678

Please sign in to comment.