From 9ca2909c80ff95b1dd4a1d92b7144d7bbfce3ca6 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 8 Apr 2021 15:58:20 +0900 Subject: Loop around the end on regex searches. --- helix-term/src/commands.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2e205fa6..0cbc3f9d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -612,8 +612,11 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) { let text = doc.text(); let start = doc.selection(view_id).cursor(); - // TODO: use find_at to find the next match after the cursor, loop around the end - if let Some(mat) = regex.find_at(contents, start) { + // use find_at to find the next match after the cursor, loop around the end + let mat = regex + .find_at(contents, start) + .or_else(|| regex.find(contents)); + if let Some(mat) = mat { let start = text.byte_to_char(mat.start()); let end = text.byte_to_char(mat.end()); let selection = Selection::single(start, end - 1); -- cgit v1.2.3-70-g09d2