diff --git a/core/src/lib.rs b/core/src/lib.rs index 7b4afd1..fb8cae4 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,2 +1,2 @@ mod text_buffer; -pub use text_buffer::{TextBuffer, TextBufferReader, TextBufferWriter}; +pub use text_buffer::{Point, TextBuffer, TextBufferReader, TextBufferWriter}; diff --git a/core/src/text_buffer/mod.rs b/core/src/text_buffer/mod.rs index cce7d14..a8e3b69 100644 --- a/core/src/text_buffer/mod.rs +++ b/core/src/text_buffer/mod.rs @@ -10,29 +10,36 @@ pub use reader::TextBufferReader; mod writer; pub use writer::TextBufferWriter; +/// A block of text, usually containing the contents of a text file. pub struct TextBuffer { contents: Rc, } +/// A location in a [TextBuffer] pub enum Point { + /// The end of the buffer End, } impl TextBuffer { + /// Create a new empty [TextBuffer] pub fn new() -> Self { Self { contents: Rope::empty(), } } + /// The size of the contents in bytes pub fn num_bytes(&self) -> usize { self.contents.total_bytes() } + /// The size of the contents in characters pub fn num_chars(&self) -> usize { self.contents.total_chars() } + /// The total number of lines in the contents pub fn num_lines(&self) -> usize { let num_chars = self.num_chars(); if num_chars == 0 { @@ -51,6 +58,7 @@ impl TextBuffer { } } + /// Insert `text` at `point`. pub fn insert_text(&mut self, text: impl Into, point: Point) { match point { Point::End => {