@@ -39,6 +39,45 @@ pub fn move_line_down(view: &mut View, count: usize) {
39 .move_selection(Direction::Forward, Granularity::Line, count);
39 .move_selection(Direction::Forward, Granularity::Line, count);
42+pub fn move_line_end(view: &mut View, count: usize) {
43+ // TODO: use a transaction
44+ let lines = selection_lines(&view.state);
46+ let positions = lines
49+ // adjust all positions to the end of the line.
50+ let line = view.state.doc.line(index);
51+ let line_start = view.state.doc.line_to_char(index);
52+ line_start + line.len_chars() - 1
54+ .map(|pos| Range::new(pos, pos));
56+ let selection = Selection::new(positions.collect(), 0);
58+ let transaction = Transaction::new(&mut view.state).with_selection(selection);
60+ transaction.apply(&mut view.state);
63+pub fn move_line_start(view: &mut View, count: usize) {
64+ let lines = selection_lines(&view.state);
66+ let positions = lines
69+ // adjust all positions to the start of the line.
70+ view.state.doc.line_to_char(index)
72+ .map(|pos| Range::new(pos, pos));
74+ let selection = Selection::new(positions.collect(), 0);
76+ let transaction = Transaction::new(&mut view.state).with_selection(selection);
78+ transaction.apply(&mut view.state);
42pub fn move_next_word_start(view: &mut View, count: usize) {
81pub fn move_next_word_start(view: &mut View, count: usize) {
43 let pos = view.state.move_pos(
82 let pos = view.state.move_pos(
44 view.state.selection.cursor(),
83 view.state.selection.cursor(),
@@ -127,46 +166,14 @@ fn selection_lines(state: &State) -> Vec<usize> {
127pub fn prepend_to_line(view: &mut View, _count: usize) {
166pub fn prepend_to_line(view: &mut View, _count: usize) {
128 view.state.mode = Mode::Insert;
167 view.state.mode = Mode::Insert;
130− let lines = selection_lines(&view.state);
169+ move_line_start(view, _count);
132− let positions = lines
135− // adjust all positions to the start of the line.
136− view.state.doc.line_to_char(index)
138− .map(|pos| Range::new(pos, pos));
140− let selection = Selection::new(positions.collect(), 0);
142− let transaction = Transaction::new(&mut view.state).with_selection(selection);
144− transaction.apply(&mut view.state);
145− // TODO: need to store into history if successful
148// A inserts at the end of each line with a selection
172// A inserts at the end of each line with a selection
149pub fn append_to_line(view: &mut View, _count: usize) {
173pub fn append_to_line(view: &mut View, _count: usize) {
150 view.state.mode = Mode::Insert;
174 view.state.mode = Mode::Insert;
152− let lines = selection_lines(&view.state);
176+ move_line_end(view, _count);
154− let positions = lines
157− // adjust all positions to the end of the line.
158− let line = view.state.doc.line(index);
159− let line_start = view.state.doc.line_to_char(index);
160− line_start + line.len_chars() - 1
162− .map(|pos| Range::new(pos, pos));
164− let selection = Selection::new(positions.collect(), 0);
166− let transaction = Transaction::new(&mut view.state).with_selection(selection);
168− transaction.apply(&mut view.state);
169− // TODO: need to store into history if successful
172// o inserts a new line after each line with a selection
179// o inserts a new line after each line with a selection