@@ -608,9 +608,10 @@ pub fn split_selection_on_newline(cx: &mut Context) {
608608// I'd probably collect all the matches right now and store the current index. The cache needs
609609// wiping if input happens.
610610
611−fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
611+fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex, extend: bool) {
612612 let text = doc.text();
613− let start = doc.selection(view_id).cursor();
613+ let selection = doc.selection(view_id);
614+ let start = selection.cursor();
614615
615616 // use find_at to find the next match after the cursor, loop around the end
616617 let mat = regex
@@ -619,7 +620,13 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
619620 if let Some(mat) = mat {
620621 let start = text.byte_to_char(mat.start());
621622 let end = text.byte_to_char(mat.end());
622− let selection = Selection::single(start, end - 1);
623+
624+ let selection = if extend {
625+ selection.clone().add(Range::new(start, end - 1))
626+ } else {
627+ Selection::single(start, end - 1)
628+ };
629+
623630 // TODO: (first_match, regex) stuff in register?
624631 doc.set_selection(view_id, selection);
625632 };
@@ -639,7 +646,7 @@ pub fn search(cx: &mut Context) {
639646 let prompt = ui::regex_prompt(cx, "search:".to_string(), move |doc, regex| {
640647 let text = doc.text();
641648 let start = doc.selection(view_id).cursor();
642− _search(doc, view_id, &contents, ®ex);
649+ _search(doc, view_id, &contents, ®ex, false);
643650
644651 // TODO: only store on enter (accept), not update
645652 register::set('\\', vec![regex.as_str().to_string()]);
@@ -648,17 +655,25 @@ pub fn search(cx: &mut Context) {
648655 cx.push_layer(Box::new(prompt));
649656}
650657
651−pub fn search_next(cx: &mut Context) {
658+pub fn _search_next(cx: &mut Context, extend: bool) {
652659 if let Some(query) = register::get('\\') {
653660 let query = query.first().unwrap();
654661 let view_id = cx.view_id;
655662 let doc = cx.doc();
656663 let contents = doc.text().slice(..).to_string();
657664 let regex = Regex::new(&query).unwrap();
658− _search(doc, view_id, &contents, ®ex);
665+ _search(doc, view_id, &contents, ®ex, extend);
659666 }
660667}
661668
669+pub fn search_next(cx: &mut Context) {
670+ _search_next(cx, false);
671+}
672+
673+pub fn extend_search_next(cx: &mut Context) {
674+ _search_next(cx, true);
675+}
676+
662677pub fn search_selection(cx: &mut Context) {
663678 let (view, doc) = cx.current();
664679 let contents = doc.text().slice(..);