Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to add word boundaries to search #4322

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl MappableCommand {
extend_search_next, "Add next search match to selection",
extend_search_prev, "Add previous search match to selection",
search_selection, "Use current selection as search pattern",
make_search_word_bounded, "Modify current search to make it word bounded",
global_search, "Global search in workspace folder",
extend_line, "Select current line, if already selected, extend to another line based on the anchor",
extend_line_below, "Select current line, if already selected, extend to next line",
Expand Down Expand Up @@ -1791,6 +1792,29 @@ fn search_selection(cx: &mut Context) {
cx.editor.set_status(msg);
}

fn make_search_word_bounded(cx: &mut Context) {
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
let regex = match cx.editor.registers.last('/') {
Some(regex) => regex,
None => return,
};
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
let mut new_regex = String::new();
mitsuhiko marked this conversation as resolved.
Show resolved Hide resolved
let mut modified = false;
if !regex.starts_with("\\b") {
new_regex.push_str("\\b");
modified = true;
}
new_regex.push_str(regex);
if !regex.ends_with("\\b") {
new_regex.push_str("\\b");
modified = true;
}
if modified {
let msg = format!("register '{}' set to '{}'", '/', &new_regex);
cx.editor.registers.get_mut('/').push(new_regex);
cx.editor.set_status(msg);
}
}

fn global_search(cx: &mut Context) {
#[derive(Debug)]
struct FileResult {
Expand Down