pub trait RopeText {
Show 34 methods
// Required method
fn text(&self) -> &Rope;
// Provided methods
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn last_line(&self) -> usize { ... }
fn offset_of_line(&self, line: usize) -> usize { ... }
fn offset_line_end(&self, offset: usize, caret: bool) -> usize { ... }
fn line_of_offset(&self, offset: usize) -> usize { ... }
fn offset_to_line_col(&self, offset: usize) -> (usize, usize) { ... }
fn offset_of_line_col(&self, line: usize, col: usize) -> usize { ... }
fn line_end_col(&self, line: usize, caret: bool) -> usize { ... }
fn line_end_offset(&self, line: usize, caret: bool) -> usize { ... }
fn line_content(&self, line: usize) -> Cow<'_, str> { ... }
fn prev_grapheme_offset(
&self,
offset: usize,
count: usize,
limit: usize,
) -> usize { ... }
fn next_grapheme_offset(
&self,
offset: usize,
count: usize,
limit: usize,
) -> usize { ... }
fn prev_code_boundary(&self, offset: usize) -> usize { ... }
fn next_code_boundary(&self, offset: usize) -> usize { ... }
fn select_word(&self, offset: usize) -> (usize, usize) { ... }
fn first_non_blank_character_on_line(&self, line: usize) -> usize { ... }
fn indent_on_line(&self, line: usize) -> String { ... }
fn slice_to_cow(&self, range: Range<usize>) -> Cow<'_, str> { ... }
fn char_indices_iter<'a, T: IntervalBounds>(
&'a self,
range: T,
) -> CharIndicesJoin<CharIndices<'a>, Map<ChunkIter<'a>, fn(&str) -> CharIndices<'_>>> ⓘ { ... }
fn num_lines(&self) -> usize { ... }
fn line_len(&self, line: usize) -> usize { ... }
fn is_line_whitespace(&self, line: usize) -> bool { ... }
fn move_left(&self, offset: usize, mode: Mode, count: usize) -> usize { ... }
fn move_right(&self, offset: usize, mode: Mode, count: usize) -> usize { ... }
fn find_nth_paragraph<F>(
&self,
offset: usize,
count: usize,
find_next: F,
) -> usize
where F: FnMut(&mut ParagraphCursor<'_>) -> Option<usize> { ... }
fn move_n_paragraphs_forward(&self, offset: usize, count: usize) -> usize { ... }
fn move_n_paragraphs_backward(&self, offset: usize, count: usize) -> usize { ... }
fn find_nth_word<F>(
&self,
offset: usize,
count: usize,
find_next: F,
) -> usize
where F: FnMut(&mut WordCursor<'_>) -> Option<usize> { ... }
fn move_n_words_forward(&self, offset: usize, count: usize) -> usize { ... }
fn move_n_wordends_forward(
&self,
offset: usize,
count: usize,
inserting: bool,
) -> usize { ... }
fn move_n_words_backward(
&self,
offset: usize,
count: usize,
mode: Mode,
) -> usize { ... }
fn move_word_backward_deletion(&self, offset: usize) -> usize { ... }
}
Required Methods§
Provided Methods§
fn len(&self) -> usize
fn is_empty(&self) -> bool
Sourcefn offset_of_line(&self, line: usize) -> usize
fn offset_of_line(&self, line: usize) -> usize
Get the offset into the rope of the start of the given line. If the line it out of bounds, then the last offset (the len) is returned.
fn offset_line_end(&self, offset: usize, caret: bool) -> usize
fn line_of_offset(&self, offset: usize) -> usize
fn offset_to_line_col(&self, offset: usize) -> (usize, usize)
Sourcefn offset_of_line_col(&self, line: usize, col: usize) -> usize
fn offset_of_line_col(&self, line: usize, col: usize) -> usize
Get the offset for a specific line and column.
This should be preferred over simply adding the column to the line offset, because it
validates better and avoids returning newlines.
let text = Rope::from("hello\nworld");
let text = RopeTextRef::new(&text);
assert_eq!(text.offset_of_line_col(0, 0), 0); // "h"
assert_eq!(text.offset_of_line_col(0, 4), 4); // "o"
assert_eq!(text.offset_of_line_col(0, 5), 5); // "\n"
assert_eq!(text.offset_of_line_col(0, 6), 5); // "\n", avoids newline
assert_eq!(text.offset_of_line_col(1, 0), 6); // "w"
assert_eq!(text.offset_of_line_col(1, 4), 10); // "d"
let text = Rope::from("hello\r\nworld");
let text = RopeTextRef::new(&text);
assert_eq!(text.offset_of_line_col(0, 0), 0); // "h"
assert_eq!(text.offset_of_line_col(0, 4), 4); // "o"
assert_eq!(text.offset_of_line_col(0, 5), 5); // "\r"
assert_eq!(text.offset_of_line_col(0, 6), 5); // "\r", avoids being in the middle
assert_eq!(text.offset_of_line_col(1, 0), 7); // "w"
assert_eq!(text.offset_of_line_col(1, 4), 11); // "d"
fn line_end_col(&self, line: usize, caret: bool) -> usize
Sourcefn line_end_offset(&self, line: usize, caret: bool) -> usize
fn line_end_offset(&self, line: usize, caret: bool) -> usize
Get the offset of the end of the line. The caret decides whether it is after the last character, or before it. If the line is out of bounds, then the last offset (the len) is returned.
let text = Rope::from("hello\nworld");
let text = RopeTextRef::new(&text);
assert_eq!(text.line_end_offset(0, false), 4); // "hell|o"
assert_eq!(text.line_end_offset(0, true), 5); // "hello|"
assert_eq!(text.line_end_offset(1, false), 10); // "worl|d"
assert_eq!(text.line_end_offset(1, true), 11); // "world|"
// Out of bounds
assert_eq!(text.line_end_offset(2, false), 11); // "world|"
Sourcefn line_content(&self, line: usize) -> Cow<'_, str>
fn line_content(&self, line: usize) -> Cow<'_, str>
Returns the content of the given line. Includes the line ending if it exists. (-> the last line won’t have a line ending) Lines past the end of the document will return an empty string.
Sourcefn prev_grapheme_offset(
&self,
offset: usize,
count: usize,
limit: usize,
) -> usize
fn prev_grapheme_offset( &self, offset: usize, count: usize, limit: usize, ) -> usize
Get the offset of the previous grapheme cluster.
fn next_grapheme_offset( &self, offset: usize, count: usize, limit: usize, ) -> usize
fn prev_code_boundary(&self, offset: usize) -> usize
fn next_code_boundary(&self, offset: usize) -> usize
Sourcefn select_word(&self, offset: usize) -> (usize, usize)
fn select_word(&self, offset: usize) -> (usize, usize)
Return the previous and end boundaries of the word under cursor.
Sourcefn first_non_blank_character_on_line(&self, line: usize) -> usize
fn first_non_blank_character_on_line(&self, line: usize) -> usize
Returns the offset of the first non-blank character on the given line. If the line is one past the last line, then the offset at the end of the rope is returned. If the line is further past that, then it defaults to the last line.
fn indent_on_line(&self, line: usize) -> String
Sourcefn slice_to_cow(&self, range: Range<usize>) -> Cow<'_, str>
fn slice_to_cow(&self, range: Range<usize>) -> Cow<'_, str>
Get the content of the rope as a Cow
string, for ‘nice’ ranges (small, and at the right
offsets) this will be a reference to the rope’s data. Otherwise, it allocates a new string.
You should be somewhat wary of requesting large parts of the rope, as it will allocate
a new string since it isn’t contiguous in memory for large chunks.
Sourcefn char_indices_iter<'a, T: IntervalBounds>(
&'a self,
range: T,
) -> CharIndicesJoin<CharIndices<'a>, Map<ChunkIter<'a>, fn(&str) -> CharIndices<'_>>> ⓘ
fn char_indices_iter<'a, T: IntervalBounds>( &'a self, range: T, ) -> CharIndicesJoin<CharIndices<'a>, Map<ChunkIter<'a>, fn(&str) -> CharIndices<'_>>> ⓘ
Iterate over (utf8_offset, char)
values in the given range.
This uses iter_chunks
and so does not allocate, compared to Self::slice_to_cow
which can
Sourcefn is_line_whitespace(&self, line: usize) -> bool
fn is_line_whitespace(&self, line: usize) -> bool
Returns true
if the given line contains no non-whitespace characters.
fn move_left(&self, offset: usize, mode: Mode, count: usize) -> usize
fn move_right(&self, offset: usize, mode: Mode, count: usize) -> usize
fn find_nth_paragraph<F>( &self, offset: usize, count: usize, find_next: F, ) -> usize
fn move_n_paragraphs_forward(&self, offset: usize, count: usize) -> usize
fn move_n_paragraphs_backward(&self, offset: usize, count: usize) -> usize
Sourcefn find_nth_word<F>(&self, offset: usize, count: usize, find_next: F) -> usize
fn find_nth_word<F>(&self, offset: usize, count: usize, find_next: F) -> usize
Find the nth (count
) word starting at offset
in either direction
depending on find_next
.
A WordCursor
is created and given to the find_next
function for the
search. The find_next
function should return None when there is no
more word found. Despite the name, find_next
can search in either
direction.
fn move_n_words_forward(&self, offset: usize, count: usize) -> usize
fn move_n_wordends_forward( &self, offset: usize, count: usize, inserting: bool, ) -> usize
fn move_n_words_backward( &self, offset: usize, count: usize, mode: Mode, ) -> usize
fn move_word_backward_deletion(&self, offset: usize) -> usize
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.