@@ -62,10 +62,7 @@ pub fn append_mode(state: &mut State, _count: usize) {
63// TODO: I, A, o and O can share a lot of the primitives.
63// TODO: I, A, o and O can share a lot of the primitives.
65−// I inserts at the start of each line with a selection
65+fn selection_lines(state: &State) -> Vec<usize> {
66−pub fn prepend_to_line(state: &mut State, _count: usize) {
67− state.mode = Mode::Insert;
69 // calculate line numbers for each selection range
66 // calculate line numbers for each selection range
70 let mut lines = state
67 let mut lines = state
71 .selection
68 .selection
@@ -77,22 +74,24 @@ pub fn prepend_to_line(state: &mut State, _count: usize) {
77 lines.sort();
74 lines.sort();
78 lines.dedup();
75 lines.dedup();
80+// I inserts at the start of each line with a selection
81+pub fn prepend_to_line(state: &mut State, _count: usize) {
82+ state.mode = Mode::Insert;
84+ let lines = selection_lines(state);
80− let positions: Vec<_> = lines
86+ let positions = lines
81 .into_iter()
87 .into_iter()
82 .map(|index| {
88 .map(|index| {
83 // adjust all positions to the start of the line.
89 // adjust all positions to the start of the line.
84 state.doc.line_to_char(index)
90 state.doc.line_to_char(index)
86− .collect();
92+ .map(|pos| Range::new(pos, pos));
88− let selection = Selection::new(
94+ let selection = Selection::new(positions.collect(), 0);
92− .map(|pos| Range::new(pos, pos))
97 let transaction = Transaction::new(state).with_selection(selection);
96 let transaction = Transaction::new(state).with_selection(selection);
@@ -104,18 +103,9 @@ pub fn prepend_to_line(state: &mut State, _count: usize) {
104pub fn append_to_line(state: &mut State, _count: usize) {
103pub fn append_to_line(state: &mut State, _count: usize) {
105 state.mode = Mode::Insert;
104 state.mode = Mode::Insert;
107− // calculate line numbers for each selection range
106+ let lines = selection_lines(state);
108− let mut lines = state
112− .map(|range| state.doc.char_to_line(range.head))
113− .collect::<Vec<_>>();
118− let positions: Vec<_> = lines
108+ let positions = lines
119 .into_iter()
109 .into_iter()
120 .map(|index| {
110 .map(|index| {
121 // adjust all positions to the end of the line.
111 // adjust all positions to the end of the line.
@@ -123,16 +113,9 @@ pub fn append_to_line(state: &mut State, _count: usize) {
123 let line_start = state.doc.line_to_char(index);
113 let line_start = state.doc.line_to_char(index);
124 line_start + line.len_chars() - 1
114 line_start + line.len_chars() - 1
126− .collect();
116+ .map(|pos| Range::new(pos, pos));
128− let selection = Selection::new(
118+ let selection = Selection::new(positions.collect(), 0);
132− .map(|pos| Range::new(pos, pos))
137 let transaction = Transaction::new(state).with_selection(selection);
120 let transaction = Transaction::new(state).with_selection(selection);
@@ -144,16 +127,7 @@ pub fn append_to_line(state: &mut State, _count: usize) {
144pub fn open_below(state: &mut State, _count: usize) {
127pub fn open_below(state: &mut State, _count: usize) {
145 state.mode = Mode::Insert;
128 state.mode = Mode::Insert;
147− // calculate line numbers for each selection range
130+ let lines = selection_lines(state);
148− let mut lines = state
152− .map(|range| state.doc.char_to_line(range.head))
153− .collect::<Vec<_>>();
158 let positions: Vec<_> = lines
132 let positions: Vec<_> = lines
159 .into_iter()
133 .into_iter()