diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 112 | ||||
-rw-r--r-- | helix-term/src/ui/mod.rs | 10 |
2 files changed, 90 insertions, 32 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5b742e43..6165c4c1 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,11 +1,11 @@ use helix_core::{ comment, coords_at_pos, graphemes, indent::TAB_WIDTH, - movement, object, pos_at_coords, + movement::{self, Direction}, + object, pos_at_coords, regex::{self, Regex}, - register, search, selection, - state::{Direction, Granularity}, - Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, Tendril, Transaction, + register, search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, + Tendril, Transaction, }; use once_cell::sync::Lazy; @@ -72,36 +72,64 @@ pub type Command = fn(cx: &mut Context); pub fn move_char_left(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Backward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Backward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_char_right(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Forward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Forward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_line_up(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Backward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Backward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_line_down(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Forward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Forward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } @@ -409,36 +437,64 @@ pub fn half_page_down(cx: &mut Context) { pub fn extend_char_left(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Backward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Backward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_char_right(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Forward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Forward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_line_up(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Backward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Backward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_line_down(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Forward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Forward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index f2376504..f7ba59cd 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -31,7 +31,7 @@ pub fn regex_prompt( prompt: String, fun: impl Fn(&mut Document, Regex) + 'static, ) -> Prompt { - let snapshot = cx.doc().state.clone(); + let snapshot = cx.doc().selection().clone(); Prompt::new( prompt, @@ -39,9 +39,10 @@ pub fn regex_prompt( move |editor: &mut Editor, input: &str, event: PromptEvent| { match event { PromptEvent::Abort => { - // revert state + // TODO: also revert doc + // TODO: also revert text let doc = &mut editor.view_mut().doc; - doc.state = snapshot.clone(); + doc.set_selection(snapshot.clone()); } PromptEvent::Validate => { // @@ -58,7 +59,8 @@ pub fn regex_prompt( let doc = &mut view.doc; // revert state to what it was before the last update - doc.state = snapshot.clone(); + // TODO: also revert text + doc.set_selection(snapshot.clone()); fun(doc, regex); |