Struct scribe::buffer::Cursor
[−]
[src]
pub struct Cursor { pub data: Rc<RefCell<GapBuffer>>, pub position: Position, // some fields omitted }
Read-only wrapper for a Position
, to allow field level access to a
buffer's cursor while simultaneously enforcing bounds-checking when
updating its value.
Fields
data: Rc<RefCell<GapBuffer>>
position: Position
Methods
impl Cursor
[src]
fn new(data: Rc<RefCell<GapBuffer>>, position: Position) -> Cursor
Initializes a cursor bound to the specified gap buffer, at the specified position.
fn move_to(&mut self, position: Position) -> bool
Moves the cursor to the specified location. The location is bounds-checked against the data and the cursor will not be updated if it is out-of-bounds.
Examples
use scribe::Buffer; use scribe::buffer::Position; let mut buffer = Buffer::new(); let in_bounds = Position{ line: 0, offset: 2 }; let out_of_bounds = Position{ line: 2, offset: 2 }; buffer.insert("scribe"); buffer.cursor.move_to(in_bounds); assert_eq!(buffer.cursor.line, 0); assert_eq!(buffer.cursor.offset, 2); buffer.cursor.move_to(out_of_bounds); assert_eq!(buffer.cursor.line, 0); assert_eq!(buffer.cursor.offset, 2);
fn move_up(&mut self)
Decrements the cursor line. The location is bounds-checked against the data and the cursor will not be updated if it is out-of-bounds.
fn move_down(&mut self)
Increments the cursor line. The location is bounds-checked against the data and the cursor will not be updated if it is out-of-bounds.
fn move_left(&mut self)
Decrements the cursor offset. The location is bounds-checked against the data and the cursor will not be updated if it is out-of-bounds.
fn move_right(&mut self)
Increments the cursor offset. The location is bounds-checked against the data and the cursor will not be updated if it is out-of-bounds.
fn move_to_start_of_line(&mut self)
Sets the cursor offset to 0: the start of the current line.
fn move_to_end_of_line(&mut self)
Moves the cursor offset to after the last character on the current line.
fn move_to_last_line(&mut self)
Moves the cursor to the last line in the buffer.
fn move_to_first_line(&mut self)
Moves the cursor to the first line in the buffer.
Methods from Deref<Target = Position>
fn add(&mut self, distance: &Distance)
Adds the specified Distance to the position.
Examples
use scribe::buffer::{Distance, Position}; let mut position = Position{ line: 1, offset: 3 }; let distance = Distance{ lines: 1, offset: 4 }; position.add(&distance); assert_eq!(position, Position{ line: 2, offset: 4 });
Trait Implementations
impl Clone for Cursor
[src]
fn clone(&self) -> Cursor
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Deref for Cursor
[src]
type Target = Position
The resulting type after dereferencing
fn deref(&self) -> &Position
The method called to dereference a value