on master help sign in
commands: add * as selection search.
commit33c67f138835d4407e076ebcf2d29322fda44114 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 22 Feb 2021, 15:14 (6 years ago) parent61ce2c9
3 files changed+12−2
helix-core/src/selection.rs+1−1 helix-term/src/commands.rs+10−1 helix-term/src/keymap.rs+1
helix-core/src/selection.rs+1−1
@@ -120,7 +120,7 @@ impl Range {
120120 // groupAt
121121
122122 #[inline]
123− pub fn fragment<'a>(&'a self, text: RopeSlice<'a>) -> Cow<'a, str> {
123+ pub fn fragment<'a, 'b: 'a>(&'a self, text: RopeSlice<'b>) -> Cow<'b, str> {
124124 Cow::from(text.slice(self.from()..self.to() + 1))
125125 }
126126}
helix-term/src/commands.rs+10−1
@@ -1,7 +1,7 @@
11use helix_core::{
22 comment, graphemes,
33 indent::TAB_WIDTH,
4− regex::Regex,
4+ regex::{self, Regex},
55 register, selection,
66 state::{Direction, Granularity, State},
77 ChangeSet, Range, Selection, Tendril, Transaction,
@@ -412,6 +412,15 @@ pub fn search_next(cx: &mut Context) {
412412 }
413413}
414414
415+pub fn search_selection(cx: &mut Context) {
416+ let doc = cx.doc();
417+ let contents = doc.text().slice(..);
418+ let query = doc.selection().primary().fragment(contents);
419+ let regex = regex::escape(&query);
420+ register::set('\\', vec![regex]);
421+ search_next(cx);
422+}
423+
415424// TODO: N -> search_prev
416425// need to loop around buffer also and show a message
417426// same for no matches
helix-term/src/keymap.rs+1
@@ -170,6 +170,7 @@ pub fn default() -> Keymaps {
170170 vec![key!('x')] => commands::select_line,
171171 vec![key!('/')] => commands::search,
172172 vec![key!('n')] => commands::search_next,
173+ vec![key!('*')] => commands::search_selection,
173174 vec![key!('u')] => commands::undo,
174175 vec![shift!('U')] => commands::redo,
175176 vec![key!('y')] => commands::yank,