From 7e4830215e22eb2fef15c1689b1dd9660aa74981 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 4 Mar 2021 14:07:35 +0900 Subject: commands: w/b/e need to apply to all selections. --- helix-term/src/commands.rs | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cb811c98..4004e18a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -128,25 +128,40 @@ pub fn move_line_start(cx: &mut Context) { pub fn move_next_word_start(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count); + let text = doc.text().slice(..); + + let selection = doc.selection().transform(|range| { + let pos = State::move_next_word_start(text, range.head, count); + Range::new(pos, pos) + }); - doc.set_selection(Selection::point(pos)); + doc.set_selection(selection); } pub fn move_prev_word_start(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count); + let text = doc.text().slice(..); - doc.set_selection(Selection::point(pos)); + let selection = doc.selection().transform(|range| { + let pos = State::move_prev_word_start(text, range.head, count); + Range::new(pos, pos) + }); + + doc.set_selection(selection); } pub fn move_next_word_end(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count); + let text = doc.text().slice(..); - doc.set_selection(Selection::point(pos)); + let selection = doc.selection().transform(|range| { + let pos = State::move_next_word_end(text, range.head, count); + Range::new(pos, pos) + }); + + doc.set_selection(selection); } pub fn move_file_start(cx: &mut Context) { @@ -168,11 +183,11 @@ pub fn move_file_end(cx: &mut Context) { pub fn extend_next_word_start(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|mut range| { - let pos = - State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count); - range.head = pos; - range + let pos = State::move_next_word_start(text, range.head, count); + Range::new(range.anchor, pos) }); doc.set_selection(selection); @@ -181,11 +196,11 @@ pub fn extend_next_word_start(cx: &mut Context) { pub fn extend_prev_word_start(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|mut range| { - let pos = - State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count); - range.head = pos; - range + let pos = State::move_prev_word_start(text, range.head, count); + Range::new(range.anchor, pos) }); doc.set_selection(selection); } @@ -193,10 +208,11 @@ pub fn extend_prev_word_start(cx: &mut Context) { pub fn extend_next_word_end(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|mut range| { - let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count); - range.head = pos; - range + let pos = State::move_next_word_end(text, range.head, count); + Range::new(range.anchor, pos) }); doc.set_selection(selection); -- cgit v1.2.3-70-g09d2