pub struct TextBuffer { /* private fields */ }
Expand description
A text buffer where characters are manipulated visually with consideration on the unicode width of characters. Characters can span more than 1 cell, therefore visually manipulating text in a 2-dimensional way should consider using the unicode width.
Implementations§
Source§impl TextBuffer
impl TextBuffer
pub fn new_from_str(content: &str) -> Self
pub fn from_ch(chars: &[&[Ch]]) -> Self
pub fn is_empty(&self) -> bool
pub fn chars(&self) -> &[Vec<Ch>]
Sourcepub fn total_chars(&self) -> usize
pub fn total_chars(&self) -> usize
return the total number of characters excluding new lines
pub fn split_line_at_point(&self, loc: Point2<usize>) -> (String, String)
pub fn split_line_at_2_points( &self, loc: Point2<usize>, loc2: Point2<usize>, ) -> (String, String, String)
Sourcepub fn cut_text_in_linear_mode(
&mut self,
start: Point2<usize>,
end: Point2<usize>,
) -> String
pub fn cut_text_in_linear_mode( &mut self, start: Point2<usize>, end: Point2<usize>, ) -> String
Remove the text within the start and end position then return the deleted text
Sourcepub fn get_text_in_linear_mode(
&self,
start: Point2<usize>,
end: Point2<usize>,
) -> String
pub fn get_text_in_linear_mode( &self, start: Point2<usize>, end: Point2<usize>, ) -> String
get the text in between start and end if selected in linear mode
Sourcepub fn get_text_in_block_mode(
&self,
start: Point2<usize>,
end: Point2<usize>,
) -> String
pub fn get_text_in_block_mode( &self, start: Point2<usize>, end: Point2<usize>, ) -> String
get the text in between start and end if selected in block mode
pub fn cut_text_in_block_mode( &mut self, start: Point2<usize>, end: Point2<usize>, ) -> String
Sourcepub fn paste_text_in_block_mode(&mut self, text_block: String)
pub fn paste_text_in_block_mode(&mut self, text_block: String)
paste the text block in the cursor location
Source§impl TextBuffer
text manipulation
This are purely manipulating text into the text buffer.
The cursor shouldn’t be move here, since it is done by the commands functions
impl TextBuffer
text manipulation This are purely manipulating text into the text buffer. The cursor shouldn’t be move here, since it is done by the commands functions
Sourcepub fn total_lines(&self) -> usize
pub fn total_lines(&self) -> usize
the total number of lines of this text canvas
Sourcepub fn numberline_wide(&self) -> usize
pub fn numberline_wide(&self) -> usize
return the number of characters to represent the line number of the last line of this text buffer
pub fn lines(&self) -> Vec<String>
Sourcepub fn first_non_blank_line(&self) -> Option<usize>
pub fn first_non_blank_line(&self) -> Option<usize>
return the first non blank line
Sourcepub fn last_non_blank_line(&self) -> Option<usize>
pub fn last_non_blank_line(&self) -> Option<usize>
return the last non blank line
Sourcepub fn line_width(&self, n: usize) -> usize
pub fn line_width(&self, n: usize) -> usize
the width of the line at line n
Sourcepub fn max_column_width(&self) -> usize
pub fn max_column_width(&self) -> usize
get the length of the widest line
Sourcepub fn max_position(&self) -> Point2<usize>
pub fn max_position(&self) -> Point2<usize>
return rectangular position starting from 0,0 to contain all the text
pub fn last_char_position(&self) -> Point2<usize>
Sourcepub fn break_line(&mut self, loc: Point2<usize>)
pub fn break_line(&mut self, loc: Point2<usize>)
break at line y and put the characters after x on the next line
pub fn join_line(&mut self, loc: Point2<usize>)
Sourcepub fn ensure_line_exist(&mut self, y: usize)
pub fn ensure_line_exist(&mut self, y: usize)
ensure line at index y exist
pub fn ensure_before_line_exist(&mut self, y: usize)
Sourcepub fn ensure_cell_exist(&mut self, loc: Point2<usize>)
pub fn ensure_cell_exist(&mut self, loc: Point2<usize>)
ensure line in index y exist and the cell at index x
pub fn ensure_before_cell_exist(&mut self, loc: Point2<usize>)
Sourcepub fn insert_char(&mut self, loc: Point2<usize>, ch: char)
pub fn insert_char(&mut self, loc: Point2<usize>, ch: char)
insert a character at this x and y and move cells after it to the right
pub fn insert_text(&mut self, loc: Point2<usize>, text: &str)
Sourcepub fn replace_char(&mut self, loc: Point2<usize>, ch: char) -> Option<char>
pub fn replace_char(&mut self, loc: Point2<usize>, ch: char) -> Option<char>
replace the character at this location
Sourcepub fn get_char(&self, loc: Point2<usize>) -> Option<char>
pub fn get_char(&self, loc: Point2<usize>) -> Option<char>
get the character at this cursor position
Sourcepub fn delete_char(&mut self, loc: Point2<usize>) -> Option<char>
pub fn delete_char(&mut self, loc: Point2<usize>) -> Option<char>
delete character at this position
Sourcepub fn get_position(&self) -> Point2<usize>
pub fn get_position(&self) -> Point2<usize>
return the position of the cursor
Source§impl TextBuffer
Command implementation here
impl TextBuffer
Command implementation here
functions that are preceeded with command also moves the cursor and highlight the texts
Note: methods that are preceeded with command
such as command_insert_char
are high level methods
which has consequences in the text buffer such as moving the cursor.
While there corresponding more primitive counter parts such as insert_char
are low level
commands, which doesn’t move the cursor location
pub fn command_insert_char(&mut self, ch: char)
pub fn command_replace_char(&mut self, ch: char) -> Option<char>
pub fn command_insert_text(&mut self, text: &str)
pub fn move_left(&mut self)
pub fn move_left_start(&mut self)
pub fn move_right(&mut self)
pub fn move_right_clamped(&mut self)
pub fn move_right_end(&mut self)
pub fn move_x(&mut self, x: usize)
pub fn move_y(&mut self, y: usize)
pub fn move_up(&mut self)
pub fn move_down(&mut self)
pub fn move_up_clamped(&mut self)
pub fn clamp_position(&self, loc: Point2<usize>) -> Point2<usize>
pub fn move_down_clamped(&mut self)
pub fn set_position(&mut self, pos: Point2<usize>)
Sourcepub fn set_position_clamped(&mut self, pos: Point2<usize>)
pub fn set_position_clamped(&mut self, pos: Point2<usize>)
set the position to the max_column of the line if it is out of bounds
pub fn command_break_line(&mut self, loc: Point2<usize>)
pub fn command_join_line(&mut self, loc: Point2<usize>)
pub fn command_delete_back(&mut self) -> Option<char>
pub fn command_delete_forward(&mut self) -> Option<char>
Trait Implementations§
Source§impl Clone for TextBuffer
impl Clone for TextBuffer
Source§fn clone(&self) -> TextBuffer
fn clone(&self) -> TextBuffer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for TextBuffer
impl Default for TextBuffer
Auto Trait Implementations§
impl Freeze for TextBuffer
impl RefUnwindSafe for TextBuffer
impl Send for TextBuffer
impl Sync for TextBuffer
impl Unpin for TextBuffer
impl UnwindSafe for TextBuffer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.