Struct kaolinite::document::Document [−][src]
pub struct Document { pub info: FileInfo, pub rows: Vec<Row>, pub modified: bool, pub size: Size, pub char_ptr: usize, pub cursor: Loc, pub offset: Loc, pub render: String, pub needs_rerender: bool, pub event_stack: EditStack, }
Expand description
A struct that contains all the basic tools necessary to manage documents
Fields
info: FileInfo
The information for the current file
rows: Vec<Row>
All the rows within the document
modified: bool
Boolean that changes when the file is edited via the event executor
size: Size
The size holds how much space the document has to render
char_ptr: usize
A pointer to the character at the current cursor position
cursor: Loc
The position within the terminal
offset: Loc
Stores information about scrolling
render: String
Render cache space for optimisation purposes
needs_rerender: bool
Toggle that determines if the document requires rerendering
event_stack: EditStack
An undo / redo stack
Implementations
Create a new document
The argument size
takes in a Size struct. This should
store information about the terminal size.
If you plan to implement things like status lines or tabs, you should subtract them from the size height, as this size is purely for the file viewport size.
Open a file at a specified path into this document.
This will also reset the cursor position, offset position, file name, contents and line ending information
Errors
Will return Err
if path
does not exist or the user does not have
permission to read from it.
Save a file
This will reset modified
to false
, as it has been saved back to it’s original file.
Errors
Will return Err
if the file path the document came from wasn’t able to be written
to, potentially because of file permission errors.
Execute an event in this document
This method is the main method that should be used to modify the document. It takes in an Event enum.
This method also takes advantage of undo & redo functionality, efficient syntax highlighting and the document modificatior indicator and moves your cursor automatically. If you change the rows in the document directly, you will not gain access to these benefits, but you can always manually handle these features if need be.
Errors
Will return Err
if the event tried to modifiy data outside the scope of the
document.
Execute an event, without the undo / redo tracking
Errors
Will error if the location is out of range
Move the cursor to a specific x and y coordinate
Errors
Will return Err
if the location provided is out of scope of the document.
Move the cursor to a specific x coordinate
Errors
Will return Err
if the location provided is out of scope of the document.
Move the cursor to a specific y coordinate
Errors
Will return Err
if the location provided is out of scope of the document.
Work out the line number text to use
A helper function that returns info about the document
in a HashMap
type.
It will return (with keys for the hashmap):
- Row number:
row
- Column number:
column
- Total rows:
total
- File name (no path):
file
- File name (full path):
full_file
- File type:
type
- Modifed indicator:
modified
- File extension:
extension
Render the document into the correct form
Take raw text and convert it into Row structs
Return a mutable reference to a row in the document
Errors
This will error if the index is out of range
Get the current position in the document
This ought to be used by the document only as it returns the display indices
Use the Document::loc
function instead.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Document
impl UnwindSafe for Document