on master help sign in
commands: w/b/e need to apply to all selections.
commit7e4830215e22eb2fef15c1689b1dd9660aa74981 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 4 Mar 2021, 14:07 (6 years ago) parentdd6db43
1 file changed+33−17
helix-term/src/commands.rs+33−17
helix-term/src/commands.rs+33−17
@@ -128,25 +128,40 @@ pub fn move_line_start(cx: &mut Context) {
128128pub fn move_next_word_start(cx: &mut Context) {
129129 let count = cx.count;
130130 let doc = cx.doc();
131− let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
131+ let text = doc.text().slice(..);
132+
133+ let selection = doc.selection().transform(|range| {
134+ let pos = State::move_next_word_start(text, range.head, count);
135+ Range::new(pos, pos)
136+ });
132137
133− doc.set_selection(Selection::point(pos));
138+ doc.set_selection(selection);
134139}
135140
136141pub fn move_prev_word_start(cx: &mut Context) {
137142 let count = cx.count;
138143 let doc = cx.doc();
139− let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count);
144+ let text = doc.text().slice(..);
140145
141− doc.set_selection(Selection::point(pos));
146+ let selection = doc.selection().transform(|range| {
147+ let pos = State::move_prev_word_start(text, range.head, count);
148+ Range::new(pos, pos)
149+ });
150+
151+ doc.set_selection(selection);
142152}
143153
144154pub fn move_next_word_end(cx: &mut Context) {
145155 let count = cx.count;
146156 let doc = cx.doc();
147− let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
157+ let text = doc.text().slice(..);
148158
149− doc.set_selection(Selection::point(pos));
159+ let selection = doc.selection().transform(|range| {
160+ let pos = State::move_next_word_end(text, range.head, count);
161+ Range::new(pos, pos)
162+ });
163+
164+ doc.set_selection(selection);
150165}
151166
152167pub fn move_file_start(cx: &mut Context) {
@@ -168,11 +183,11 @@ pub fn move_file_end(cx: &mut Context) {
168183pub fn extend_next_word_start(cx: &mut Context) {
169184 let count = cx.count;
170185 let doc = cx.doc();
186+ let text = doc.text().slice(..);
187+
171188 let selection = doc.selection().transform(|mut range| {
172− let pos =
173− State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
174− range.head = pos;
175− range
189+ let pos = State::move_next_word_start(text, range.head, count);
190+ Range::new(range.anchor, pos)
176191 });
177192
178193 doc.set_selection(selection);
@@ -181,11 +196,11 @@ pub fn extend_next_word_start(cx: &mut Context) {
181196pub fn extend_prev_word_start(cx: &mut Context) {
182197 let count = cx.count;
183198 let doc = cx.doc();
199+ let text = doc.text().slice(..);
200+
184201 let selection = doc.selection().transform(|mut range| {
185− let pos =
186− State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count);
187− range.head = pos;
188− range
202+ let pos = State::move_prev_word_start(text, range.head, count);
203+ Range::new(range.anchor, pos)
189204 });
190205 doc.set_selection(selection);
191206}
@@ -193,10 +208,11 @@ pub fn extend_prev_word_start(cx: &mut Context) {
193208pub fn extend_next_word_end(cx: &mut Context) {
194209 let count = cx.count;
195210 let doc = cx.doc();
211+ let text = doc.text().slice(..);
212+
196213 let selection = doc.selection().transform(|mut range| {
197− let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
198− range.head = pos;
199− range
214+ let pos = State::move_next_word_end(text, range.head, count);
215+ Range::new(range.anchor, pos)
200216 });
201217
202218 doc.set_selection(selection);