pub struct Document<'a> { /* private fields */ }
Expand description
Allows you to do functions on the current line.
Implementations§
Source§impl<'a> Document<'a>
impl<'a> Document<'a>
Sourcepub fn get_cursor_pos(&self) -> usize
pub fn get_cursor_pos(&self) -> usize
Returns the current cursor position.
Sourcepub fn get_whole_line(&self) -> &str
pub fn get_whole_line(&self) -> &str
Returns the whole of the data stored in the document.
Sourcepub fn get_char_relative_to_cursor(&self, offset: isize) -> Option<char>
pub fn get_char_relative_to_cursor(&self, offset: isize) -> Option<char>
Returns the char before the cursor. If the cursor is at zero or the doc is empty, will return None.
Sourcepub fn text_before_cursor(&self) -> &str
pub fn text_before_cursor(&self) -> &str
Returns the text up until the cursor position. The cursor appears one ahead.
Sourcepub fn text_after_cursor(&self) -> &str
pub fn text_after_cursor(&self) -> &str
Returns the text after the cursor.
Sourcepub fn get_word_before_cursor(&self) -> &str
pub fn get_word_before_cursor(&self) -> &str
Returns a word before the cursor. A word is delimited by the start or end of the document, and space.
Sourcepub fn get_word_after_cursor(&self) -> &str
pub fn get_word_after_cursor(&self) -> &str
Returns a word after the cursor. This includes the char on the cursor. A word is delimited by the start or end of the document, and space.
Sourcepub fn get_word_before_cursor_with_space(&self) -> &str
pub fn get_word_before_cursor_with_space(&self) -> &str
Returns a word before the cursor including the spaces.
Sourcepub fn get_word_after_cursor_with_space(&self) -> &str
pub fn get_word_after_cursor_with_space(&self) -> &str
Returns a word after the cursor including the spaces.
Sourcepub fn get_word_before_cursor_until_sep(&self, sep: char) -> &str
pub fn get_word_before_cursor_until_sep(&self, sep: char) -> &str
Returns the word before the cursor until a separator is reached.
Examples found in repository?
7 fn get_suggestions(&self, doc: Document) -> Vec<Suggestion> {
8 let mut suggestions = vec![
9 Suggestion::new("find", "Find something"),
10 Suggestion::new("go", "Go somewhere"),
11 Suggestion::new("die", "kills something"),
12 Suggestion::new("flame", "flames something"),
13 Suggestion::new("Blank_Desc", ""),
14 ];
15 let filter = doc.get_word_before_cursor_until_sep(' ');
16 if filter == "" {
17 suggestions
18 } else {
19 suggestions.retain(|v| v.get_name().contains(filter));
20 suggestions
21 }
22 }
Sourcepub fn get_word_after_cursor_until_sep(&self, sep: char) -> &str
pub fn get_word_after_cursor_until_sep(&self, sep: char) -> &str
Returns the word after the cursor until a separator is reached.
Sourcepub fn get_word_before_cursor_until_sep_ignore_next_to_cursor(
&self,
sep: char,
) -> &str
pub fn get_word_before_cursor_until_sep_ignore_next_to_cursor( &self, sep: char, ) -> &str
Returns a word before the cursor until a separator is reached. Ignores the char next to the cursor.
Sourcepub fn get_word_after_cursor_until_sep_ignore_next_to_cursor(
&self,
sep: char,
) -> &str
pub fn get_word_after_cursor_until_sep_ignore_next_to_cursor( &self, sep: char, ) -> &str
Returns a word after the cursor until a separator is reached. Ignores the char next to the cursor.