pub struct Buffer { /* private fields */ }
Implementations§
Source§impl Buffer
impl Buffer
pub fn new(text: impl Into<Rope>) -> Self
Sourcepub fn set_pristine(&mut self)
pub fn set_pristine(&mut self)
Mark the buffer as pristine (aka ‘saved’)
pub fn is_pristine(&self) -> bool
pub fn set_cursor_before(&mut self, cursor: CursorMode)
pub fn set_cursor_after(&mut self, cursor: CursorMode)
pub fn atomic_rev(&self) -> Arc<AtomicU64>
pub fn init_content(&mut self, content: Rope)
pub fn reload( &mut self, content: Rope, set_pristine: bool, ) -> (Rope, RopeDelta, InvalLines)
pub fn detect_indent(&mut self, default: impl FnOnce() -> IndentStyle)
pub fn indent_style(&self) -> IndentStyle
pub fn indent_unit(&self) -> &'static str
pub fn line_ending(&self) -> LineEnding
pub fn set_line_ending(&mut self, line_ending: LineEnding)
pub fn reset_edit_type(&mut self)
Sourcepub fn edit<'a, I, E, S>(
&mut self,
edits: I,
edit_type: EditType,
) -> (Rope, RopeDelta, InvalLines)
pub fn edit<'a, I, E, S>( &mut self, edits: I, edit_type: EditType, ) -> (Rope, RopeDelta, InvalLines)
Apply edits, normalizes line endings before applying.
Returns (Text before delta, delta, invalidated lines)
pub fn normalize_line_endings( &mut self, ) -> Option<(Rope, RopeDelta, InvalLines)>
pub fn do_undo( &mut self, ) -> Option<(Rope, RopeDelta, InvalLines, Option<CursorMode>)>
pub fn do_redo( &mut self, ) -> Option<(Rope, RopeDelta, InvalLines, Option<CursorMode>)>
pub fn move_word_forward(&self, offset: usize) -> usize
pub fn move_word_backward(&self, offset: usize, mode: Mode) -> usize
pub fn char_at_offset(&self, offset: usize) -> Option<char>
Trait Implementations§
Source§impl RopeText for Buffer
impl RopeText for Buffer
fn text(&self) -> &Rope
fn len(&self) -> usize
fn is_empty(&self) -> bool
Source§fn 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)
Source§fn 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. Read more
This should be preferred over simply adding the column to the line offset, because it validates better and avoids returning newlines. Read more
fn line_end_col(&self, line: usize, caret: bool) -> usize
Source§fn 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. Read more
Source§fn 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.
Source§fn 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
Source§fn 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.
Source§fn 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
Source§fn 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.Source§fn 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 canSource§fn 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
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
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more