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

Methods

impl Cursor
[src]

Initializes a cursor bound to the specified gap buffer, at the specified position.

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);

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.

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.

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.

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.

Sets the cursor offset to 0: the start of the current line.

Moves the cursor offset to after the last character on the current line.

Moves the cursor to the last line in the buffer.

Moves the cursor to the first line in the buffer.

Methods from Deref<Target = Position>

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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Deref for Cursor
[src]

The resulting type after dereferencing

The method called to dereference a value

impl DerefMut for Cursor
[src]

The method called to mutably dereference a value