diff options
author | Blaž Hrastnik | 2021-04-09 15:21:13 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-04-09 15:21:13 +0000 |
commit | 73f4abbb37e399cdb422fb723827d256142a9df3 (patch) | |
tree | edff5f0cc15ace84e41bd8427469becc641e3e6b /helix-term | |
parent | 35b4fe4cd0a23310a3d71242e97ad6c1d081b7c2 (diff) |
N as extend with search (for now, N should be search_prev).
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 27 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 1 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 1 |
3 files changed, 23 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 53ec2fbf..98e8b20c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -608,9 +608,10 @@ pub fn split_selection_on_newline(cx: &mut Context) { // I'd probably collect all the matches right now and store the current index. The cache needs // wiping if input happens. -fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) { +fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex, extend: bool) { let text = doc.text(); - let start = doc.selection(view_id).cursor(); + let selection = doc.selection(view_id); + let start = selection.cursor(); // use find_at to find the next match after the cursor, loop around the end let mat = regex @@ -619,7 +620,13 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) { 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); + + let selection = if extend { + selection.clone().add(Range::new(start, end - 1)) + } else { + Selection::single(start, end - 1) + }; + // TODO: (first_match, regex) stuff in register? doc.set_selection(view_id, selection); }; @@ -639,7 +646,7 @@ pub fn search(cx: &mut Context) { let prompt = ui::regex_prompt(cx, "search:".to_string(), move |doc, regex| { let text = doc.text(); let start = doc.selection(view_id).cursor(); - _search(doc, view_id, &contents, ®ex); + _search(doc, view_id, &contents, ®ex, false); // TODO: only store on enter (accept), not update register::set('\\', vec![regex.as_str().to_string()]); @@ -648,17 +655,25 @@ pub fn search(cx: &mut Context) { cx.push_layer(Box::new(prompt)); } -pub fn search_next(cx: &mut Context) { +pub fn _search_next(cx: &mut Context, extend: bool) { if let Some(query) = register::get('\\') { let query = query.first().unwrap(); let view_id = cx.view_id; let doc = cx.doc(); let contents = doc.text().slice(..).to_string(); let regex = Regex::new(&query).unwrap(); - _search(doc, view_id, &contents, ®ex); + _search(doc, view_id, &contents, ®ex, extend); } } +pub fn search_next(cx: &mut Context) { + _search_next(cx, false); +} + +pub fn extend_search_next(cx: &mut Context) { + _search_next(cx, true); +} + pub fn search_selection(cx: &mut Context) { let (view, doc) = cx.current(); let contents = doc.text().slice(..); diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 06b190aa..e20c8ebf 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -199,6 +199,7 @@ pub fn default() -> Keymaps { key!('/') => commands::search, // ? for search_reverse key!('n') => commands::search_next, + shift!('N') => commands::extend_search_next, // N for search_prev key!('*') => commands::search_selection, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index d32f7864..35693d7b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -61,6 +61,7 @@ impl EditorView { view.area.width - OFFSET, view.area.height.saturating_sub(1), ); // - 1 for statusline + self.render_buffer(doc, view, area, surface, theme, is_focused); // if we're not at the edge of the screen, draw a right border |