diff --git a/Cargo.lock b/Cargo.lock index 7bec6ad..3095a1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -687,7 +687,7 @@ dependencies = [ [[package]] name = "ropey" version = "2.0.0-alpha" -source = "git+https://github.com/cessen/ropey?branch=2.0-alpha#013c3cf6d3c2647b79af3f346fff7610efe37c5a" +source = "git+https://github.com/cessen/ropey?branch=2.0-alpha#157c806694729f4cefc9bab12e62d8df2e9e0dbf" dependencies = [ "str_indices", ] diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 1eb7da3..d79c0d1 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -356,7 +356,7 @@ impl Editor { let range = mark.range(); // Do nothing if there's nothing to delete. - if range.end == self.buffer.text.len_bytes() { + if range.end == self.buffer.text.len() { return; } @@ -392,7 +392,7 @@ impl Editor { } pub fn cursor_to_end_of_buffer(&mut self) { - let end = self.buffer.text.len_bytes(); + let end = self.buffer.text.len(); self.buffer.mark_sets[self.c_msi].clear(); self.buffer.mark_sets[self.c_msi].add_mark(Mark::new(end, end)); @@ -481,8 +481,8 @@ impl Editor { if temp_index == mark.head { // We were already at the bottom. - mark.head = self.buffer.text.len_bytes(); - mark.tail = self.buffer.text.len_bytes(); + mark.head = self.buffer.text.len(); + mark.tail = self.buffer.text.len(); mark.hh_pos = None; } else { mark.head = temp_index; diff --git a/src/formatter.rs b/src/formatter.rs index 39d47d8..7f21511 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -138,7 +138,7 @@ impl LineFormatter { // If we reached the end of the text, return the last char index. let end_i = byte_idx - byte_offset + i; let end_last_i = byte_idx - byte_offset + last_i; - if buf.len_bytes() == end_i { + if buf.len() == end_i { return end_i; } else { return end_last_i; @@ -175,9 +175,9 @@ impl LineFormatter { } } else if offset_byte_v_pos >= block_v_dim as isize { // If we're off the end of the block. - byte_idx = (byte_idx + block.len_bytes() - byte_offset).min(buf.len_bytes()); + byte_idx = (byte_idx + block.len() - byte_offset).min(buf.len()); v_offset -= block_v_dim as isize - byte_v_pos as isize; - if byte_idx == buf.len_bytes() { + if byte_idx == buf.len() { break; } } else { @@ -498,7 +498,7 @@ fn tab_stop_from_vis_pos(pos: usize, tab_width: usize) -> usize { pub fn find_good_break(slice: &RopeSlice, lower_limit: usize, byte_idx: usize) -> usize { const WS_CHARS: &[char] = &[' ', ' ', '\t']; - let slice_len = slice.len_bytes(); + let slice_len = slice.len(); let byte_idx = byte_idx.min(slice_len); let lower_limit = lower_limit.min(slice_len); @@ -555,7 +555,7 @@ pub fn byte_range_from_block_index(slice: &RopeSlice, block_idx: usize) -> (usiz pub fn block_index_and_range(slice: &RopeSlice, byte_idx: usize) -> (usize, (usize, usize)) { let mut block_index = byte_idx / LINE_BLOCK_LENGTH; let mut range = byte_range_from_block_index(slice, block_index); - if byte_idx >= range.1 && range.1 < slice.len_bytes() { + if byte_idx >= range.1 && range.1 < slice.len() { block_index += 1; range = byte_range_from_block_index(slice, block_index); } @@ -563,7 +563,7 @@ pub fn block_index_and_range(slice: &RopeSlice, byte_idx: usize) -> (usize, (usi } pub fn block_count(slice: &RopeSlice) -> usize { - let byte_count = slice.len_bytes(); + let byte_count = slice.len(); let mut last_idx = byte_count.saturating_sub(1) / LINE_BLOCK_LENGTH; let range = byte_range_from_block_index(slice, last_idx + 1); diff --git a/src/graphemes.rs b/src/graphemes.rs index 39e95d8..dd729b4 100644 --- a/src/graphemes.rs +++ b/src/graphemes.rs @@ -39,13 +39,13 @@ pub fn nth_prev_grapheme_boundary(slice: &RopeSlice, byte_idx: usize, n: usize) /// Finds the previous grapheme boundary before the given char position. pub fn prev_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize { // Bounds check - debug_assert!(byte_idx <= slice.len_bytes()); + debug_assert!(byte_idx <= slice.len()); // Get the chunk with our byte index in it. let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx); // Set up the grapheme cursor. - let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true); + let mut gc = GraphemeCursor::new(byte_idx, slice.len(), true); // Find the previous grapheme cluster boundary. loop { @@ -80,18 +80,18 @@ pub fn nth_next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize, n: usize) /// Finds the next grapheme boundary after the given char position. pub fn next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize { // Bounds check - debug_assert!(byte_idx <= slice.len_bytes()); + debug_assert!(byte_idx <= slice.len()); // Get the chunk with our byte index in it. let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx); // Set up the grapheme cursor. - let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true); + let mut gc = GraphemeCursor::new(byte_idx, slice.len(), true); // Find the next grapheme cluster boundary. loop { match gc.next_boundary(chunk, chunk_byte_idx) { - Ok(None) => return slice.len_bytes(), + Ok(None) => return slice.len(), Ok(Some(n)) => return n, Err(GraphemeIncomplete::NextChunk) => { chunk_byte_idx += chunk.len(); @@ -110,13 +110,13 @@ pub fn next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize { /// Returns whether the given char position is a grapheme boundary. pub fn is_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> bool { // Bounds check - debug_assert!(byte_idx <= slice.len_bytes()); + debug_assert!(byte_idx <= slice.len()); // Get the chunk with our byte index in it. let (chunk, chunk_byte_idx) = slice.chunk(byte_idx); // Set up the grapheme cursor. - let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true); + let mut gc = GraphemeCursor::new(byte_idx, slice.len(), true); // Determine if the given position is a grapheme cluster boundary. loop { @@ -150,7 +150,7 @@ impl<'a> RopeGraphemes<'a> { chunks: chunks, cur_chunk: first_chunk, cur_chunk_start: 0, - cursor: GraphemeCursor::new(0, slice.len_bytes(), true), + cursor: GraphemeCursor::new(0, slice.len(), true), } } } diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index f72862f..8a6edff 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -500,9 +500,9 @@ impl TermUI { // Percentage position in document // TODO: use view instead of cursor for calculation if there is more // than one cursor. - let percentage: usize = if editor.buffer.text.len_bytes() > 0 { + let percentage: usize = if editor.buffer.text.len() > 0 { (((editor.buffer.mark_sets[editor.c_msi].main().unwrap().head as f32) - / (editor.buffer.text.len_bytes() as f32)) + / (editor.buffer.text.len() as f32)) * 100.0) as usize } else { 100 @@ -677,10 +677,9 @@ impl TermUI { if at_cursor { // Calculate the cell coordinates at which to draw the cursor - let pos_x = editor.formatter.get_horizontal( - &self.editor.buffer.text, - self.editor.buffer.text.len_bytes(), - ); + let pos_x = editor + .formatter + .get_horizontal(&self.editor.buffer.text, self.editor.buffer.text.len()); let mut px = pos_x as isize + screen_col; let mut py = screen_line - 1; if px > c2.1 as isize { diff --git a/src/term_ui/smallstring.rs b/src/term_ui/smallstring.rs index 80bcb66..d9fbd35 100644 --- a/src/term_ui/smallstring.rs +++ b/src/term_ui/smallstring.rs @@ -40,7 +40,7 @@ impl SmallString { /// Creates a new `SmallString` with the same contents as the given `&str`. pub fn from_rope_slice(text: &RopeSlice) -> Self { - let mut string = SmallString::with_capacity(text.len_bytes()); + let mut string = SmallString::with_capacity(text.len()); let mut idx = 0; for chunk in text.chunks() { unsafe { string.insert_bytes(idx, chunk.as_bytes()) }; diff --git a/sub_crates/backend/src/transaction.rs b/sub_crates/backend/src/transaction.rs index 1d767d6..40c5f77 100644 --- a/sub_crates/backend/src/transaction.rs +++ b/sub_crates/backend/src/transaction.rs @@ -318,7 +318,7 @@ impl Transaction { } } } - debug_assert!(i <= text.len_bytes()); + debug_assert!(i <= text.len()); } /// Applies the inverse of the Transaction to a Rope. @@ -351,7 +351,7 @@ impl Transaction { } } } - debug_assert!(i <= text.len_bytes()); + debug_assert!(i <= text.len()); } /// Applies the Transaction to a set of Marks.