Update code for Ropey 2 method rename.
This commit is contained in:
parent
cd2314905a
commit
22d9f4f660
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -687,7 +687,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ropey"
|
name = "ropey"
|
||||||
version = "2.0.0-alpha"
|
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 = [
|
dependencies = [
|
||||||
"str_indices",
|
"str_indices",
|
||||||
]
|
]
|
||||||
|
|
|
@ -356,7 +356,7 @@ impl Editor {
|
||||||
let range = mark.range();
|
let range = mark.range();
|
||||||
|
|
||||||
// Do nothing if there's nothing to delete.
|
// Do nothing if there's nothing to delete.
|
||||||
if range.end == self.buffer.text.len_bytes() {
|
if range.end == self.buffer.text.len() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_to_end_of_buffer(&mut self) {
|
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].clear();
|
||||||
self.buffer.mark_sets[self.c_msi].add_mark(Mark::new(end, end));
|
self.buffer.mark_sets[self.c_msi].add_mark(Mark::new(end, end));
|
||||||
|
@ -481,8 +481,8 @@ impl Editor {
|
||||||
|
|
||||||
if temp_index == mark.head {
|
if temp_index == mark.head {
|
||||||
// We were already at the bottom.
|
// We were already at the bottom.
|
||||||
mark.head = self.buffer.text.len_bytes();
|
mark.head = self.buffer.text.len();
|
||||||
mark.tail = self.buffer.text.len_bytes();
|
mark.tail = self.buffer.text.len();
|
||||||
mark.hh_pos = None;
|
mark.hh_pos = None;
|
||||||
} else {
|
} else {
|
||||||
mark.head = temp_index;
|
mark.head = temp_index;
|
||||||
|
|
|
@ -138,7 +138,7 @@ impl LineFormatter {
|
||||||
// If we reached the end of the text, return the last char index.
|
// If we reached the end of the text, return the last char index.
|
||||||
let end_i = byte_idx - byte_offset + i;
|
let end_i = byte_idx - byte_offset + i;
|
||||||
let end_last_i = byte_idx - byte_offset + last_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;
|
return end_i;
|
||||||
} else {
|
} else {
|
||||||
return end_last_i;
|
return end_last_i;
|
||||||
|
@ -175,9 +175,9 @@ impl LineFormatter {
|
||||||
}
|
}
|
||||||
} else if offset_byte_v_pos >= block_v_dim as isize {
|
} else if offset_byte_v_pos >= block_v_dim as isize {
|
||||||
// If we're off the end of the block.
|
// 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;
|
v_offset -= block_v_dim as isize - byte_v_pos as isize;
|
||||||
if byte_idx == buf.len_bytes() {
|
if byte_idx == buf.len() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
pub fn find_good_break(slice: &RopeSlice, lower_limit: usize, byte_idx: usize) -> usize {
|
||||||
const WS_CHARS: &[char] = &[' ', ' ', '\t'];
|
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 byte_idx = byte_idx.min(slice_len);
|
||||||
let lower_limit = lower_limit.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)) {
|
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 block_index = byte_idx / LINE_BLOCK_LENGTH;
|
||||||
let mut range = byte_range_from_block_index(slice, block_index);
|
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;
|
block_index += 1;
|
||||||
range = byte_range_from_block_index(slice, block_index);
|
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 {
|
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 mut last_idx = byte_count.saturating_sub(1) / LINE_BLOCK_LENGTH;
|
||||||
|
|
||||||
let range = byte_range_from_block_index(slice, last_idx + 1);
|
let range = byte_range_from_block_index(slice, last_idx + 1);
|
||||||
|
|
|
@ -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.
|
/// Finds the previous grapheme boundary before the given char position.
|
||||||
pub fn prev_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
pub fn prev_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
||||||
// Bounds check
|
// Bounds check
|
||||||
debug_assert!(byte_idx <= slice.len_bytes());
|
debug_assert!(byte_idx <= slice.len());
|
||||||
|
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
// Set up the grapheme cursor.
|
// 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.
|
// Find the previous grapheme cluster boundary.
|
||||||
loop {
|
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.
|
/// Finds the next grapheme boundary after the given char position.
|
||||||
pub fn next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
pub fn next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
||||||
// Bounds check
|
// Bounds check
|
||||||
debug_assert!(byte_idx <= slice.len_bytes());
|
debug_assert!(byte_idx <= slice.len());
|
||||||
|
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
// Set up the grapheme cursor.
|
// 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.
|
// Find the next grapheme cluster boundary.
|
||||||
loop {
|
loop {
|
||||||
match gc.next_boundary(chunk, chunk_byte_idx) {
|
match gc.next_boundary(chunk, chunk_byte_idx) {
|
||||||
Ok(None) => return slice.len_bytes(),
|
Ok(None) => return slice.len(),
|
||||||
Ok(Some(n)) => return n,
|
Ok(Some(n)) => return n,
|
||||||
Err(GraphemeIncomplete::NextChunk) => {
|
Err(GraphemeIncomplete::NextChunk) => {
|
||||||
chunk_byte_idx += chunk.len();
|
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.
|
/// Returns whether the given char position is a grapheme boundary.
|
||||||
pub fn is_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> bool {
|
pub fn is_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> bool {
|
||||||
// Bounds check
|
// Bounds check
|
||||||
debug_assert!(byte_idx <= slice.len_bytes());
|
debug_assert!(byte_idx <= slice.len());
|
||||||
|
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (chunk, chunk_byte_idx) = slice.chunk(byte_idx);
|
let (chunk, chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
// Set up the grapheme cursor.
|
// 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.
|
// Determine if the given position is a grapheme cluster boundary.
|
||||||
loop {
|
loop {
|
||||||
|
@ -150,7 +150,7 @@ impl<'a> RopeGraphemes<'a> {
|
||||||
chunks: chunks,
|
chunks: chunks,
|
||||||
cur_chunk: first_chunk,
|
cur_chunk: first_chunk,
|
||||||
cur_chunk_start: 0,
|
cur_chunk_start: 0,
|
||||||
cursor: GraphemeCursor::new(0, slice.len_bytes(), true),
|
cursor: GraphemeCursor::new(0, slice.len(), true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,9 +500,9 @@ impl TermUI {
|
||||||
// Percentage position in document
|
// Percentage position in document
|
||||||
// TODO: use view instead of cursor for calculation if there is more
|
// TODO: use view instead of cursor for calculation if there is more
|
||||||
// than one cursor.
|
// 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.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
|
* 100.0) as usize
|
||||||
} else {
|
} else {
|
||||||
100
|
100
|
||||||
|
@ -677,10 +677,9 @@ impl TermUI {
|
||||||
|
|
||||||
if at_cursor {
|
if at_cursor {
|
||||||
// Calculate the cell coordinates at which to draw the cursor
|
// Calculate the cell coordinates at which to draw the cursor
|
||||||
let pos_x = editor.formatter.get_horizontal(
|
let pos_x = editor
|
||||||
&self.editor.buffer.text,
|
.formatter
|
||||||
self.editor.buffer.text.len_bytes(),
|
.get_horizontal(&self.editor.buffer.text, self.editor.buffer.text.len());
|
||||||
);
|
|
||||||
let mut px = pos_x as isize + screen_col;
|
let mut px = pos_x as isize + screen_col;
|
||||||
let mut py = screen_line - 1;
|
let mut py = screen_line - 1;
|
||||||
if px > c2.1 as isize {
|
if px > c2.1 as isize {
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl SmallString {
|
||||||
|
|
||||||
/// Creates a new `SmallString` with the same contents as the given `&str`.
|
/// Creates a new `SmallString` with the same contents as the given `&str`.
|
||||||
pub fn from_rope_slice(text: &RopeSlice) -> Self {
|
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;
|
let mut idx = 0;
|
||||||
for chunk in text.chunks() {
|
for chunk in text.chunks() {
|
||||||
unsafe { string.insert_bytes(idx, chunk.as_bytes()) };
|
unsafe { string.insert_bytes(idx, chunk.as_bytes()) };
|
||||||
|
|
|
@ -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.
|
/// 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.
|
/// Applies the Transaction to a set of Marks.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user