@@ -128,25 +128,40 @@ pub fn move_line_start(cx: &mut Context) {
128pub fn move_next_word_start(cx: &mut Context) {
128pub fn move_next_word_start(cx: &mut Context) {
129 let count = cx.count;
129 let count = cx.count;
130 let doc = cx.doc();
130 let doc = cx.doc();
131+ let text = doc.text().slice(..);
133+ let selection = doc.selection().transform(|range| {
131− let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
134+ let pos = State::move_next_word_start(text, range.head, count);
135+ Range::new(pos, pos)
133− doc.set_selection(Selection::point(pos));
138+ doc.set_selection(selection);
136pub fn move_prev_word_start(cx: &mut Context) {
141pub fn move_prev_word_start(cx: &mut Context) {
137 let count = cx.count;
142 let count = cx.count;
138 let doc = cx.doc();
143 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(..);
146+ let selection = doc.selection().transform(|range| {
147+ let pos = State::move_prev_word_start(text, range.head, count);
148+ Range::new(pos, pos)
141− doc.set_selection(Selection::point(pos));
151+ doc.set_selection(selection);
144pub fn move_next_word_end(cx: &mut Context) {
154pub fn move_next_word_end(cx: &mut Context) {
145 let count = cx.count;
155 let count = cx.count;
146 let doc = cx.doc();
156 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(..);
159+ let selection = doc.selection().transform(|range| {
160+ let pos = State::move_next_word_end(text, range.head, count);
161+ Range::new(pos, pos)
149− doc.set_selection(Selection::point(pos));
164+ doc.set_selection(selection);
152pub fn move_file_start(cx: &mut Context) {
167pub fn move_file_start(cx: &mut Context) {
@@ -168,11 +183,11 @@ pub fn move_file_end(cx: &mut Context) {
168pub fn extend_next_word_start(cx: &mut Context) {
183pub fn extend_next_word_start(cx: &mut Context) {
169 let count = cx.count;
184 let count = cx.count;
170 let doc = cx.doc();
185 let doc = cx.doc();
186+ let text = doc.text().slice(..);
171 let selection = doc.selection().transform(|mut range| {
188 let selection = doc.selection().transform(|mut range| {
173− State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
189+ let pos = State::move_next_word_start(text, range.head, count);
174− range.head = pos;
190+ Range::new(range.anchor, pos)
178 doc.set_selection(selection);
193 doc.set_selection(selection);
@@ -181,11 +196,11 @@ pub fn extend_next_word_start(cx: &mut Context) {
181pub fn extend_prev_word_start(cx: &mut Context) {
196pub fn extend_prev_word_start(cx: &mut Context) {
182 let count = cx.count;
197 let count = cx.count;
183 let doc = cx.doc();
198 let doc = cx.doc();
199+ let text = doc.text().slice(..);
184 let selection = doc.selection().transform(|mut range| {
201 let selection = doc.selection().transform(|mut range| {
186− State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count);
202+ let pos = State::move_prev_word_start(text, range.head, count);
187− range.head = pos;
203+ Range::new(range.anchor, pos)
190 doc.set_selection(selection);
205 doc.set_selection(selection);
@@ -193,10 +208,11 @@ pub fn extend_prev_word_start(cx: &mut Context) {
193pub fn extend_next_word_end(cx: &mut Context) {
208pub fn extend_next_word_end(cx: &mut Context) {
194 let count = cx.count;
209 let count = cx.count;
195 let doc = cx.doc();
210 let doc = cx.doc();
211+ let text = doc.text().slice(..);
196 let selection = doc.selection().transform(|mut range| {
213 let selection = doc.selection().transform(|mut range| {
197− let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
214+ let pos = State::move_next_word_end(text, range.head, count);
198− range.head = pos;
215+ Range::new(range.anchor, pos)
202 doc.set_selection(selection);
218 doc.set_selection(selection);