Struct kaolinite::row::Row[][src]

pub struct Row {
    pub text: Vec<char>,
    pub indices: Vec<usize>,
    pub modified: bool,
    pub tokens: Vec<Token>,
    pub needs_rerender: bool,
}
Expand description

A struct that contains all the basic tools necessary to manage rows in a document

Fields

text: Vec<char>

All the characters within the row

indices: Vec<usize>

Corresponding display widths for each character

modified: bool

A tool for determining if the row has been edited

use kaolinite::row::Row;
let tab_width = 4;
let mut row = Row::new("Hello", tab_width);
assert_eq!(row.modified, false);
row.insert(5, ", world!", tab_width);
assert_eq!(row.modified, true);
row.modified = false;
assert_eq!(row.modified, false);

This is ideal for optimisation

tokens: Vec<Token>

Tokens for this row

needs_rerender: bool

Implementations

Create a new row from raw text

Insert text at a position

Errors

Will return Err if start is out of range of the row

Remove text in a range

This takes in an inclusive or exclusive range: .. and ..= only.

Errors

Will return Err if range is out of range of the row

Splits this row into two separate rows

Errors

Will return Err if idx is out of range of the row

Joins this row with another row

Retrieve the indices of word boundaries

// Opening a file,
use kaolinite::document::Document;
let mut doc = Document::new((10, 10));
// Imagine if test.txt were `The quick brown fox`
doc.open("examples/test.txt").expect("Failed to open file");
// This would get the word boundaries of the first row: [0, 4, 10, 16, 19]
println!("{:?}", doc.row(0).unwrap().words());

Find the next word in this row from the character index

Find the previous word in this row from the character index

Render part of the row When trying to render X axis offset, this is the ideal function to use

"He好llo好" // 0..
"e好llo好"  // 1..
"好llo好"   // 2..
" llo好"    // 3..
"llo好"     // 4..
"lo好"      // 5..
"o好"       // 6..
"好"        // 7..
" "         // 8..
""          // 9..

This also handles double width characters by inserting whitespace when half of the character is off the screen

Render the entire row, with tabs converted into spaces

Render this row as is, with no tab interference

Find the character length of this row

Determine if the row is empty

Find the display width of this row

Calculate the character pointer from a display index

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.