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: 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
Implementations
sourceimpl Editor
impl Editor
pub fn new(filename: Option<String>, terminal: Box<dyn Console>) -> Self
sourcefn process_event(&mut self) -> Result<(), Error>
fn process_event(&mut self) -> Result<(), Error>
Main event processing method. An event can be either be a keystroke or a mouse click
sourcefn process_keystroke(&mut self, pressed_key: Key)
fn process_keystroke(&mut self, pressed_key: Key)
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).
sourcefn process_mouse_event(&mut self, mouse_event: MouseEvent)
fn process_mouse_event(&mut self, mouse_event: MouseEvent)
React to a mouse event. If the mouse is being pressed, record the coordinates, and
sourcefn enter_insert_mode(&mut self)
fn enter_insert_mode(&mut self)
Switch the Editor mode to Insert
sourcefn enter_normal_mode(&mut self)
fn enter_normal_mode(&mut self)
Switch the Editor mode to Normal
sourcefn start_receiving_command(&mut self)
fn start_receiving_command(&mut self)
Make the Editor ready to receive a command
sourcefn start_receiving_search_pattern(&mut self)
fn start_receiving_search_pattern(&mut self)
Make the Editor ready to receive a search pattern
sourcefn stop_receiving_command(&mut self)
fn stop_receiving_command(&mut self)
Stop receiving a command
sourcefn is_receiving_command(&self) -> bool
fn is_receiving_command(&self) -> bool
Return whether the Editor is currently receiving a command
sourcefn is_autocompleting_command(&self) -> bool
fn is_autocompleting_command(&self) -> bool
Return whether the Editor is currently autosuggesting command based on the user input
sourcefn reset_autocompletions(&mut self)
fn reset_autocompletions(&mut self)
Reset the state of the command autocompletion
fn pop_normal_command_repetitions(&mut self) -> usize
sourcefn process_received_command(&mut self)
fn process_received_command(&mut self)
Receive a command entered by the user in the command prompt and take appropriate actions
sourcefn autocomplete_command(&mut self)
fn autocomplete_command(&mut self)
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.
sourcefn cycle_through_command_suggestions(&mut self)
fn cycle_through_command_suggestions(&mut self)
Cycle through the possible command suggestions by incrementing (or resetting)
the current_autocompletion_index
value.
sourcefn save(&mut self, new_name: &str)
fn save(&mut self, new_name: &str)
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.
sourcefn save_to_swap_file(&mut self)
fn save_to_swap_file(&mut self)
Save all current unsaved edits to a swap file, allowing a seamless recovery in case of a crash.
sourcefn quit(&mut self, force: bool)
fn quit(&mut self, force: bool)
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.
sourcefn process_search_command(&mut self, search_pattern: &str)
fn process_search_command(&mut self, search_pattern: &str)
Search for the user-provided pattern in the document text, and move the cursor to the first occurence, if any.
sourcefn reset_search(&mut self)
fn reset_search(&mut self)
Reset all state related to text search back to the default values.
sourcefn revert_to_main_screen(&mut self)
fn revert_to_main_screen(&mut self)
Revert the editor back to the main screen, containing the document text.
sourcefn process_normal_command(&mut self, key: Key)
fn process_normal_command(&mut self, key: Key)
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
sourcefn process_normal_command_n_times(&mut self, c: char, n: usize)
fn process_normal_command_n_times(&mut self, c: char, n: usize)
Execute the provided normal movement command n timess
sourcefn process_insert_command(&mut self, pressed_key: Key)
fn process_insert_command(&mut self, pressed_key: Key)
Process a command issued when the editor is in normal mode
sourcefn get_row(&self, index: RowIndex) -> Option<&Row>
fn get_row(&self, index: RowIndex) -> Option<&Row>
Return the row located at the provide row index if it exists
sourcefn current_row(&self) -> &Row
fn current_row(&self) -> &Row
Return the Row object associated to the current cursor position / vertical offset
sourcefn current_row_index(&self) -> RowIndex
fn current_row_index(&self) -> RowIndex
Return the index of the row associated to the current cursor position / vertical offset
sourcefn previous_row_index(&self) -> RowIndex
fn previous_row_index(&self) -> RowIndex
Return the RowIndex
corresponding to the previous row, with respect to the current one
sourcefn next_row_index(&self) -> RowIndex
fn next_row_index(&self) -> RowIndex
Return the RowIndex
corresponding to the previous row, with respect to the current one
sourcefn current_x_position(&self) -> usize
fn current_x_position(&self) -> usize
Return the current x position, taking the offset into account
sourcefn current_grapheme(&self) -> &str
fn current_grapheme(&self) -> &str
Return the character currently under the cursor
sourcefn previous_grapheme(&self) -> &str
fn previous_grapheme(&self) -> &str
Return the character currently at the left of the cursor
sourcefn current_line_number(&self) -> LineNumber
fn current_line_number(&self) -> LineNumber
Return the line number associated to the current cursor position / vertical offset
sourcefn delete_current_line(&mut self)
fn delete_current_line(&mut self)
Delete the line currently under the cursor
sourcefn delete_current_grapheme(&mut self)
fn delete_current_grapheme(&mut self)
Delete the grapheme currently under the cursor
sourcefn insert_newline_after_current_line(&mut self)
fn insert_newline_after_current_line(&mut self)
Insert a newline after the current one, move cursor to it in insert mode
sourcefn insert_newline_before_current_line(&mut self)
fn insert_newline_before_current_line(&mut self)
Insert a newline before the current one, move cursor to it in insert mode
sourcefn append_to_line(&mut self)
fn append_to_line(&mut self)
Move to the end of the line, and switch to Insert mode
sourcefn join_current_line_with_next_one(&mut self)
fn join_current_line_with_next_one(&mut self)
Join the current line with the next one, using a space as a separator
sourcefn goto_start_or_end_of_paragraph(&mut self, boundary: &Boundary, times: usize)
fn goto_start_or_end_of_paragraph(&mut self, boundary: &Boundary, times: usize)
Move the cursor to the next line after the current paraghraph, or the line before the current paragraph.
sourcefn goto_start_or_end_of_document(&mut self, boundary: &Boundary)
fn goto_start_or_end_of_document(&mut self, boundary: &Boundary)
Move the cursor either to the first or last line of the document
sourcefn goto_start_or_end_of_line(&mut self, boundary: &Boundary)
fn goto_start_or_end_of_line(&mut self, boundary: &Boundary)
Move the cursor either to the start or end of the line
sourcefn goto_start_or_end_of_word(&mut self, boundary: &Boundary, times: usize)
fn goto_start_or_end_of_word(&mut self, boundary: &Boundary, times: usize)
Move to the start of the next word or previous one.
sourcefn goto_first_non_whitespace(&mut self)
fn goto_first_non_whitespace(&mut self)
Move the cursor to the first non whitespace character in the line
sourcefn goto_middle_of_terminal(&mut self)
fn goto_middle_of_terminal(&mut self)
Move the cursor to the middle of the terminal
sourcefn goto_first_line_of_terminal(&mut self)
fn goto_first_line_of_terminal(&mut self)
Move the cursor to the middle of the terminal
sourcefn goto_last_line_of_terminal(&mut self)
fn goto_last_line_of_terminal(&mut self)
Move the cursor to the last line of the terminal
sourcefn goto_percentage_in_document(&mut self, percent: usize)
fn goto_percentage_in_document(&mut self, percent: usize)
Move to {n}% in the file
sourcefn goto_matching_closing_symbol(&mut self)
fn goto_matching_closing_symbol(&mut self)
Go to the matching closing symbol (whether that’s a quote, curly/square/regular brace, etc).
sourcefn goto_next_search_match(&mut self)
fn goto_next_search_match(&mut self)
Move to the first character of the next search match
sourcefn goto_previous_search_match(&mut self)
fn goto_previous_search_match(&mut self)
Move to the first character of the previous search match
sourcefn goto_line(&mut self, line_number: LineNumber, x_position: usize)
fn goto_line(&mut self, line_number: LineNumber, x_position: usize)
Move the cursor to the nth line in the file and adjust the viewport
fn goto_position(&mut self, pos: Position)
sourcefn goto_x_y(&mut self, x: usize, y: RowIndex)
fn goto_x_y(&mut self, x: usize, y: RowIndex)
Move the cursor to the first column of the nth line
sourcefn move_cursor(&mut self, direction: &Direction, times: usize)
fn move_cursor(&mut self, direction: &Direction, times: usize)
Move the cursor up/down/left/right by adjusting its x/y position
sourcefn move_cursor_to_position_y(&mut self, y: RowIndex)
fn move_cursor_to_position_y(&mut self, y: RowIndex)
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
)
sourcefn move_cursor_to_position_x(&mut self, x: usize)
fn move_cursor_to_position_x(&mut self, x: usize)
Move the cursor to the associated x non-negative position, adjusting the x offset if that takes the cursor out of the current view.
sourcefn undo_last_operation(&mut self)
fn undo_last_operation(&mut self)
Undo the last registered operation in history
sourcefn get_x_index_of_currently_selected_suggestion(&self) -> usize
fn get_x_index_of_currently_selected_suggestion(&self) -> usize
Return the x index of the first character of the currently selected autocompletion suggestion
sourcefn refresh_screen(&mut self) -> Result<(), Error>
fn refresh_screen(&mut self) -> Result<(), Error>
Refresh the screen by displaying all rows and bars
sourcefn generate_status(&self) -> String
fn generate_status(&self) -> String
Generate the content of the status bar
sourcefn draw_status_bar(&self)
fn draw_status_bar(&self)
Display the content of the status bar to the screen
sourcefn draw_message_bar(&self)
fn draw_message_bar(&self)
Display the content of the message bar to the screen
sourcefn generate_command_autocompletion_message(&self) -> String
fn generate_command_autocompletion_message(&self) -> String
Generate the command autocompletion message, that will be displayed in the message bar
sourcefn display_message(&mut self, message: String)
fn display_message(&mut self, message: String)
Make sure the provided message gets displayed in the message bar
sourcefn reset_message(&mut self)
fn reset_message(&mut self)
Erase the currently displayed message
sourcefn display_welcome_message(&self)
fn display_welcome_message(&self)
Display a welcome message, when no document has been opened
sourcefn draw_help_screen(&mut self)
fn draw_help_screen(&mut self)
Display the automatically generated help panel on the screen
sourcefn draw_rows(&self)
fn draw_rows(&self)
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 ~
.
sourcefn draw_row(&self, row: &Row, line_number: LineNumber)
fn draw_row(&self, row: &Row, line_number: LineNumber)
Display the content of a particular document row to the screen
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Editor
impl !Send for Editor
impl !Sync for Editor
impl Unpin for Editor
impl !UnwindSafe for Editor
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more