on master help sign in
commands: add * as selection search.
33c67f1Blaž Hrastnik
helix-core/src/selection.rs+1−1
@@ -120,7 +120,7 @@ impl Range {
120 // groupAt
120 // groupAt
121
121
122 #[inline]
122 #[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> {
124 Cow::from(text.slice(self.from()..self.to() + 1))
124 Cow::from(text.slice(self.from()..self.to() + 1))
125 }
125 }
126}
126}
helix-term/src/commands.rs+10−1
@@ -1,7 +1,7 @@
1use helix_core::{
1use helix_core::{
2 comment, graphemes,
2 comment, graphemes,
3 indent::TAB_WIDTH,
3 indent::TAB_WIDTH,
4− regex::Regex,
4+ regex::{self, Regex},
5 register, selection,
5 register, selection,
6 state::{Direction, Granularity, State},
6 state::{Direction, Granularity, State},
7 ChangeSet, Range, Selection, Tendril, Transaction,
7 ChangeSet, Range, Selection, Tendril, Transaction,
@@ -412,6 +412,15 @@ pub fn search_next(cx: &mut Context) {
412 }
412 }
413}
413}
414
414
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+
415// TODO: N -> search_prev
424// TODO: N -> search_prev
416// need to loop around buffer also and show a message
425// need to loop around buffer also and show a message
417// same for no matches
426// same for no matches
helix-term/src/keymap.rs+1
@@ -170,6 +170,7 @@ pub fn default() -> Keymaps {
170 vec![key!('x')] => commands::select_line,
170 vec![key!('x')] => commands::select_line,
171 vec![key!('/')] => commands::search,
171 vec![key!('/')] => commands::search,
172 vec![key!('n')] => commands::search_next,
172 vec![key!('n')] => commands::search_next,
173+ vec![key!('*')] => commands::search_selection,
173 vec![key!('u')] => commands::undo,
174 vec![key!('u')] => commands::undo,
174 vec![shift!('U')] => commands::redo,
175 vec![shift!('U')] => commands::redo,
175 vec![key!('y')] => commands::yank,
176 vec![key!('y')] => commands::yank,