pub struct Editor {
Show 21 fields should_quit: bool, cursor_position: Position, document: Document, offset: ViewportOffset, message: String, mode: Mode, command_buffer: String, command_suggestions: Vec<String>, current_autocompletion_index: usize, config: Config, normal_command_buffer: Vec<String>, mouse_event_buffer: Vec<Position>, search_matches: Vec<(Position, Position)>, current_search_match_index: usize, alternate_screen: bool, last_saved_hash: u64, terminal: Box<dyn Console>, unsaved_edits: u8, row_prefix_length: u8, help_message: String, history: History,
}

Fields

should_quit: boolcursor_position: Positiondocument: Documentoffset: ViewportOffsetmessage: Stringmode: Modecommand_buffer: Stringcommand_suggestions: Vec<String>current_autocompletion_index: usizeconfig: Confignormal_command_buffer: Vec<String>mouse_event_buffer: Vec<Position>search_matches: Vec<(Position, Position)>current_search_match_index: usizealternate_screen: boollast_saved_hash: u64terminal: Box<dyn Console>unsaved_edits: u8row_prefix_length: u8help_message: Stringhistory: History

Implementations

Main screen rendering loop

Main event processing method. An event can be either be a keystroke or a mouse click

React to a keystroke. The reaction itself depends on the editor mode (insert, command, normal) or whether the editor is currently receiving a user input command (eg: “:q”, etc).

React to a mouse event. If the mouse is being pressed, record the coordinates, and

Switch the Editor mode to Insert

Switch the Editor mode to Normal

Make the Editor ready to receive a command

Make the Editor ready to receive a search pattern

Stop receiving a command

Return whether the Editor is currently receiving a command

Return whether the Editor is currently autosuggesting command based on the user input

Reset the state of the command autocompletion

Receive a command entered by the user in the command prompt and take appropriate actions

Determine which commands could be autocompleted into based on the current state of the user provided command.

If only one command suggestion is found, it will be automatically selected. Else, the command_suggestions vector will be populated with the possible commands.

Cycle through the possible command suggestions by incrementing (or resetting) the current_autocompletion_index value.

Save the current document to the target file.

If no filename is associated to the current document, an error message will be displayed.

When the document is saved, all trailing spaces will automatically be deleted.

Save all current unsaved edits to a swap file, allowing a seamless recovery in case of a crash.

Change the internal state of the Editor to mark it as ready to quit.

If force is set to false and some unsaved edits were made, an error will be displayed in the message bar.

Search for the user-provided pattern in the document text, and move the cursor to the first occurence, if any.

Reset all state related to text search back to the default values.

Revert the editor back to the main screen, containing the document text.

Process navigation command issued in normal mode, that will resolve in having the cursor be moved around the document.

Note: some commands are accumulative (ie: 2j will move the cursor down twice) and some are not (ie: g will move the cursor to the start of the document only once). A buffer is maintained for the accumulative commands, and is purged when the last char of the command is received. For now, only commans of the form * are supported and I’m not sure I’m planning to support anything more complex than that.

Execute the provided normal movement command n timess

Process a command issued when the editor is in normal mode

Return the row located at the provide row index if it exists

Return the Row object associated to the current cursor position / vertical offset

Return the index of the row associated to the current cursor position / vertical offset

Return the RowIndex corresponding to the previous row, with respect to the current one

Return the RowIndex corresponding to the previous row, with respect to the current one

Return the current x position, taking the offset into account

Return the character currently under the cursor

Return the character currently at the left of the cursor

Return the line number associated to the current cursor position / vertical offset

Delete the line currently under the cursor

Delete the grapheme currently under the cursor

Insert a newline after the current one, move cursor to it in insert mode

Insert a newline before the current one, move cursor to it in insert mode

Move to the end of the line, and switch to Insert mode

Join the current line with the next one, using a space as a separator

Move the cursor to the next line after the current paraghraph, or the line before the current paragraph.

Move the cursor either to the first or last line of the document

Move the cursor either to the start or end of the line

Move to the start of the next word or previous one.

Move the cursor to the first non whitespace character in the line

Move the cursor to the middle of the terminal

Move the cursor to the middle of the terminal

Move the cursor to the last line of the terminal

Move to {n}% in the file

Go to the matching closing symbol (whether that’s a quote, curly/square/regular brace, etc).

Move to the first character of the next search match

Move to the first character of the previous search match

Move the cursor to the nth line in the file and adjust the viewport

Move the cursor to the first column of the nth line

Move the cursor up/down/left/right by adjusting its x/y position

Move the cursor to the given y RowIndex.

Depending on the both the current and destination cursor position, multiple scenarii can unfold:

  • we move the cursor in the same view by simply changing the cursor y position
  • we move the cursor to a different view, by changing both the cursor y position and the offset, and positioning the cursor at the middle of that new view
  • we move the cursor to the first view in the document, by changing the cursor y position and setting the y offset to 0
  • we move the cursor to the last view in the document, by changing the cursor y position and setting the y offset to (len_doc - view_height)

Move the cursor to the associated x non-negative position, adjusting the x offset if that takes the cursor out of the current view.

Return whether the document has seen some edits since the last save

Undo the last registered operation in history

Return the x index of the first character of the currently selected autocompletion suggestion

Refresh the screen by displaying all rows and bars

Generate the content of the status bar

Display the content of the status bar to the screen

Display the content of the message bar to the screen

Generate the command autocompletion message, that will be displayed in the message bar

Make sure the provided message gets displayed in the message bar

Erase the currently displayed message

Display a welcome message, when no document has been opened

Display the automatically generated help panel on the screen

Iterate over each visible document rows and display it on the screen. If no document is currently opened, display the welcome message. If the document is shorter than the viewport height, display empty lines as ~.

Display the content of a particular document row to the screen

Trait Implementations

Formats the value using the given formatter. Read more

Serialize this value into the given Serde serializer. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.