summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs50
1 files changed, 28 insertions, 22 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 8570bee1..cc4fab05 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -116,12 +116,8 @@ 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 = doc.state.move_pos(
- doc.selection().cursor(),
- Direction::Forward,
- Granularity::Word,
- count,
- );
+ // TODO: count
+ let pos = State::move_next_word_start(&doc.text().slice(..), doc.selection().cursor());
doc.set_selection(Selection::point(pos));
}
@@ -129,12 +125,7 @@ pub fn move_next_word_start(cx: &mut Context) {
pub fn move_prev_word_start(cx: &mut Context) {
let count = cx.count;
let doc = cx.doc();
- let pos = doc.state.move_pos(
- doc.selection().cursor(),
- Direction::Backward,
- Granularity::Word,
- count,
- );
+ let pos = State::move_prev_word_start(&doc.text().slice(..), doc.selection().cursor());
doc.set_selection(Selection::point(pos));
}
@@ -163,19 +154,36 @@ pub fn move_file_end(cx: &mut Context) {
pub fn extend_next_word_start(cx: &mut Context) {
let count = cx.count;
- let selection = cx
- .doc()
- .state
- .extend_selection(Direction::Forward, Granularity::Word, count);
+ let doc = cx.doc();
+ let mut selection = doc.selection().transform(|mut range| {
+ let pos = State::move_next_word_start(&doc.text().slice(..), doc.selection().cursor());
+ range.head = pos;
+ range
+ }); // TODO: count
+
cx.doc().set_selection(selection);
}
pub fn extend_prev_word_start(cx: &mut Context) {
let count = cx.count;
- let selection = cx
- .doc()
- .state
- .extend_selection(Direction::Backward, Granularity::Word, count);
+ let doc = cx.doc();
+ let mut selection = doc.selection().transform(|mut range| {
+ let pos = State::move_prev_word_start(&doc.text().slice(..), doc.selection().cursor());
+ range.head = pos;
+ range
+ }); // TODO: count
+ cx.doc().set_selection(selection);
+}
+
+pub fn extend_next_word_end(cx: &mut Context) {
+ let count = cx.count;
+ let doc = cx.doc();
+ let mut selection = doc.selection().transform(|mut range| {
+ let pos = State::move_next_word_end(&doc.text().slice(..), doc.selection().cursor(), count);
+ range.head = pos;
+ range
+ }); // TODO: count
+
cx.doc().set_selection(selection);
}
@@ -320,8 +328,6 @@ pub fn split_selection(cx: &mut Context) {
// # update state
// }
- let snapshot = cx.doc().state.clone();
-
let prompt = ui::regex_prompt(cx, "split:".to_string(), |doc, regex| {
let text = &doc.text().slice(..);
let selection = selection::split_on_matches(text, doc.selection(), &regex);