aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-04 05:07:35 +0000
committerBlaž Hrastnik2021-03-04 05:09:39 +0000
commit7e4830215e22eb2fef15c1689b1dd9660aa74981 (patch)
tree00617ee766068a4c525f2ac4c17b7478c59bb44f /helix-term
parentdd6db430134914538df8a2d664891abf81e23a7e (diff)
commands: w/b/e need to apply to all selections.
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs50
1 files 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);