1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
extern crate frappe; extern crate ropey; extern crate unicode_segmentation; pub mod buffer; pub mod history; pub mod cursor; pub mod trie; mod command; mod cache; pub use buffer::Buffer; pub use history::History; pub use cursor::Cursor; pub use trie::TrieState; pub use command::CursorCmd; pub use cache::LineCache; pub(crate) trait Ropey { fn starts_with(&self, prefix: &str) -> bool; } impl Ropey for ropey::Rope { fn starts_with(&self, prefix: &str) -> bool { Ropey::starts_with(&self.slice(..), prefix) } } impl<'a> Ropey for ropey::RopeSlice<'a> { fn starts_with(&self, prefix: &str) -> bool { let prefix_num_chars = prefix.chars().count(); if self.len_chars() < prefix_num_chars { return false } prefix.chars() .enumerate() .take_while(|&(i, char)| self.char(i) == char) .map(|(i, _)| i) .max() == prefix_num_chars.checked_sub(1) } }