@@ -101,7 +101,7 @@ impl State {
101 let line = text.char_to_line(pos);
101 let line = text.char_to_line(pos);
102 let start = text.line_to_char(line);
102 let start = text.line_to_char(line);
103 let pos = std::cmp::max(
103 let pos = std::cmp::max(
104− nth_prev_grapheme_boundary(&text.slice(..), pos, count),
104+ nth_prev_grapheme_boundary(text.slice(..), pos, count),
107 Range::new(if extend { range.anchor } else { pos }, pos)
107 Range::new(if extend { range.anchor } else { pos }, pos)
@@ -113,14 +113,14 @@ impl State {
113 // subtract another 1 because the line ends with \n
113 // subtract another 1 because the line ends with \n
114 let end = text.line_to_char(line + 1).saturating_sub(2);
114 let end = text.line_to_char(line + 1).saturating_sub(2);
115 let pos =
115 let pos =
116− std::cmp::min(nth_next_grapheme_boundary(&text.slice(..), pos, count), end);
116+ std::cmp::min(nth_next_grapheme_boundary(text.slice(..), pos, count), end);
117 Range::new(if extend { range.anchor } else { pos }, pos)
117 Range::new(if extend { range.anchor } else { pos }, pos)
119− (_, Granularity::Line) => move_vertically(&text.slice(..), dir, range, count, extend),
119+ (_, Granularity::Line) => move_vertically(text.slice(..), dir, range, count, extend),
123− pub fn move_next_word_start(slice: &RopeSlice, mut pos: usize) -> usize {
123+ pub fn move_next_word_start(slice: RopeSlice, mut pos: usize) -> usize {
124 // TODO: confirm it's fine without using graphemes, I think it should be
124 // TODO: confirm it's fine without using graphemes, I think it should be
125 let ch = slice.char(pos);
125 let ch = slice.char(pos);
126 let next = slice.char(pos.saturating_add(1));
126 let next = slice.char(pos.saturating_add(1));
@@ -143,7 +143,7 @@ impl State {
146− pub fn move_prev_word_start(slice: &RopeSlice, mut pos: usize) -> usize {
146+ pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize) -> usize {
147 // TODO: confirm it's fine without using graphemes, I think it should be
147 // TODO: confirm it's fine without using graphemes, I think it should be
148 let ch = slice.char(pos);
148 let ch = slice.char(pos);
149 let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
149 let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
@@ -169,7 +169,7 @@ impl State {
169 pos.saturating_add(1)
169 pos.saturating_add(1)
172− pub fn move_next_word_end(slice: &RopeSlice, mut pos: usize, _count: usize) -> usize {
172+ pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, _count: usize) -> usize {
173 // TODO: confirm it's fine without using graphemes, I think it should be
173 // TODO: confirm it's fine without using graphemes, I think it should be
174 let ch = slice.char(pos);
174 let ch = slice.char(pos);
175 let next = slice.char(pos.saturating_add(1));
175 let next = slice.char(pos.saturating_add(1));
@@ -217,7 +217,7 @@ impl State {
219/// Convert a character index to (line, column) coordinates.
219/// Convert a character index to (line, column) coordinates.
220−pub fn coords_at_pos(text: &RopeSlice, pos: usize) -> Position {
220+pub fn coords_at_pos(text: RopeSlice, pos: usize) -> Position {
221 let line = text.char_to_line(pos);
221 let line = text.char_to_line(pos);
222 let line_start = text.line_to_char(line);
222 let line_start = text.line_to_char(line);
223 let col = text.slice(line_start..pos).len_chars();
223 let col = text.slice(line_start..pos).len_chars();
@@ -225,14 +225,14 @@ pub fn coords_at_pos(text: &RopeSlice, pos: usize) -> Position {
227/// Convert (line, column) coordinates to a character index.
227/// Convert (line, column) coordinates to a character index.
228−pub fn pos_at_coords(text: &RopeSlice, coords: Position) -> usize {
228+pub fn pos_at_coords(text: RopeSlice, coords: Position) -> usize {
229 let Position { row, col } = coords;
229 let Position { row, col } = coords;
230 let line_start = text.line_to_char(row);
230 let line_start = text.line_to_char(row);
231 nth_next_grapheme_boundary(text, line_start, col)
231 nth_next_grapheme_boundary(text, line_start, col)
234fn move_vertically(
234fn move_vertically(
235− text: &RopeSlice,
235+ text: RopeSlice,
236 dir: Direction,
236 dir: Direction,
237 range: Range,
237 range: Range,
238 count: usize,
238 count: usize,
@@ -287,7 +287,7 @@ fn categorize(ch: char) -> Category {
290−fn skip_over_next<F>(slice: &RopeSlice, pos: &mut usize, fun: F)
290+fn skip_over_next<F>(slice: RopeSlice, pos: &mut usize, fun: F)
292 F: Fn(char) -> bool,
292 F: Fn(char) -> bool,
@@ -301,7 +301,7 @@ where
304−fn skip_over_prev<F>(slice: &RopeSlice, pos: &mut usize, fun: F)
304+fn skip_over_prev<F>(slice: RopeSlice, pos: &mut usize, fun: F)
306 F: Fn(char) -> bool,
306 F: Fn(char) -> bool,
@@ -323,34 +323,36 @@ mod test {
324 fn test_coords_at_pos() {
324 fn test_coords_at_pos() {
325 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
325 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
326− assert_eq!(coords_at_pos(&text.slice(..), 0), (0, 0).into());
326+ let slice = text.slice(..);
327+ assert_eq!(coords_at_pos(slice, 0), (0, 0).into());
327− assert_eq!(coords_at_pos(&text.slice(..), 5), (0, 5).into()); // position on \n
328+ assert_eq!(coords_at_pos(slice, 5), (0, 5).into()); // position on \n
328− assert_eq!(coords_at_pos(&text.slice(..), 6), (1, 0).into()); // position on w
329+ assert_eq!(coords_at_pos(slice, 6), (1, 0).into()); // position on w
329− assert_eq!(coords_at_pos(&text.slice(..), 7), (1, 1).into()); // position on o
330+ assert_eq!(coords_at_pos(slice, 7), (1, 1).into()); // position on o
330− assert_eq!(coords_at_pos(&text.slice(..), 10), (1, 4).into()); // position on d
331+ assert_eq!(coords_at_pos(slice, 10), (1, 4).into()); // position on d
334 fn test_pos_at_coords() {
335 fn test_pos_at_coords() {
335 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
336 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
336− assert_eq!(pos_at_coords(&text.slice(..), (0, 0).into()), 0);
337+ let slice = text.slice(..);
338+ assert_eq!(pos_at_coords(slice, (0, 0).into()), 0);
337− assert_eq!(pos_at_coords(&text.slice(..), (0, 5).into()), 5); // position on \n
339+ assert_eq!(pos_at_coords(slice, (0, 5).into()), 5); // position on \n
338− assert_eq!(pos_at_coords(&text.slice(..), (1, 0).into()), 6); // position on w
340+ assert_eq!(pos_at_coords(slice, (1, 0).into()), 6); // position on w
339− assert_eq!(pos_at_coords(&text.slice(..), (1, 1).into()), 7); // position on o
341+ assert_eq!(pos_at_coords(slice, (1, 1).into()), 7); // position on o
340− assert_eq!(pos_at_coords(&text.slice(..), (1, 4).into()), 10); // position on d
342+ assert_eq!(pos_at_coords(slice, (1, 4).into()), 10); // position on d
344 fn test_vertical_move() {
346 fn test_vertical_move() {
345 let text = Rope::from("abcd\nefg\nwrs");
347 let text = Rope::from("abcd\nefg\nwrs");
346− let pos = pos_at_coords(&text.slice(..), (0, 4).into());
347 let slice = text.slice(..);
348 let slice = text.slice(..);
349+ let pos = pos_at_coords(slice, (0, 4).into());
349 let range = Range::new(pos, pos);
351 let range = Range::new(pos, pos);
350 assert_eq!(
352 assert_eq!(
351 coords_at_pos(
353 coords_at_pos(
353− move_vertically(&slice, Direction::Forward, range, 1, false).head
355+ move_vertically(slice, Direction::Forward, range, 1, false).head
355 (1, 2).into()
357 (1, 2).into()