@@ -122,7 +122,7 @@ impl State {
122 // TODO: move all selections according to normal cursor move semantics by collapsing it
122 // TODO: move all selections according to normal cursor move semantics by collapsing it
123 // into cursors and moving them vertically
123 // into cursors and moving them vertically
125− let ranges = self.selection.ranges.iter().map(|range| {
125+ self.selection.transform(|range| {
126 // let pos = if !range.is_empty() {
126 // let pos = if !range.is_empty() {
127 // // if selection already exists, bump it to the start or end of current select first
127 // // if selection already exists, bump it to the start or end of current select first
128 // if dir == Direction::Backward {
128 // if dir == Direction::Backward {
@@ -134,10 +134,7 @@ impl State {
134 let pos = self.move_pos(range.head, dir, granularity, count);
134 let pos = self.move_pos(range.head, dir, granularity, count);
136 SelectionRange::new(pos, pos)
136 SelectionRange::new(pos, pos)
139− Selection::new(ranges.collect(), self.selection.primary_index)
140− // TODO: update selection in state via transaction
143 pub fn extend_selection(
140 pub fn extend_selection(
@@ -146,13 +143,10 @@ impl State {
146 granularity: Granularity,
143 granularity: Granularity,
147 count: usize,
144 count: usize,
148 ) -> Selection {
145 ) -> Selection {
149− let ranges = self.selection.ranges.iter().map(|range| {
146+ self.selection.transform(|range| {
150 let pos = self.move_pos(range.head, dir, granularity, count);
147 let pos = self.move_pos(range.head, dir, granularity, count);
151 SelectionRange::new(range.anchor, pos)
148 SelectionRange::new(range.anchor, pos)
154− Selection::new(ranges.collect(), self.selection.primary_index)
155− // TODO: update selection in state via transaction
@@ -203,7 +197,6 @@ mod test {
203 fn test_coords_at_pos() {
197 fn test_coords_at_pos() {
204 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
198 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
205 assert_eq!(coords_at_pos(&text.slice(..), 0), (0, 0));
199 assert_eq!(coords_at_pos(&text.slice(..), 0), (0, 0));
206− // TODO: what is the coordinate of newline?
207 assert_eq!(coords_at_pos(&text.slice(..), 5), (0, 5)); // position on \n
200 assert_eq!(coords_at_pos(&text.slice(..), 5), (0, 5)); // position on \n
208 assert_eq!(coords_at_pos(&text.slice(..), 6), (1, 0)); // position on w
201 assert_eq!(coords_at_pos(&text.slice(..), 6), (1, 0)); // position on w
209 assert_eq!(coords_at_pos(&text.slice(..), 7), (1, 1)); // position on o
202 assert_eq!(coords_at_pos(&text.slice(..), 7), (1, 1)); // position on o