@@ -60,8 +60,86 @@ pub fn append_mode(state: &mut State, _count: usize) {
63+// TODO: I, A, o and O can share a lot of the primitives.
63// I inserts at the start of each line with a selection
65// I inserts at the start of each line with a selection
66+pub fn prepend_to_line(state: &mut State, _count: usize) {
67+ state.mode = Mode::Insert;
69+ // calculate line numbers for each selection range
70+ let mut lines = state
74+ .map(|range| state.doc.char_to_line(range.head))
75+ .collect::<Vec<_>>();
80+ let positions: Vec<_> = lines
83+ // adjust all positions to the end of the line.
84+ let line_start = state.doc.line_to_char(index);
89+ let selection = Selection::new(
93+ .map(|pos| Range::new(pos, pos))
98+ let transaction = Transaction::new(state).with_selection(selection);
100+ transaction.apply(state);
101+ // TODO: need to store into history if successful
64// A inserts at the end of each line with a selection
104// A inserts at the end of each line with a selection
105+pub fn append_to_line(state: &mut State, _count: usize) {
106+ state.mode = Mode::Insert;
108+ // calculate line numbers for each selection range
109+ let mut lines = state
113+ .map(|range| state.doc.char_to_line(range.head))
114+ .collect::<Vec<_>>();
119+ let positions: Vec<_> = lines
122+ // adjust all positions to the end of the line.
123+ let line = state.doc.line(index);
124+ let line_start = state.doc.line_to_char(index);
125+ line_start + line.len_chars() - 1
129+ let selection = Selection::new(
133+ .map(|pos| Range::new(pos, pos))
138+ let transaction = Transaction::new(state).with_selection(selection);
140+ transaction.apply(state);
141+ // TODO: need to store into history if successful
66// o inserts a new line after each line with a selection
144// o inserts a new line after each line with a selection
67pub fn open_below(state: &mut State, _count: usize) {
145pub fn open_below(state: &mut State, _count: usize) {