forked from mars/breed
Add a bunch more actions
This commit is contained in:
parent
2d3c15e571
commit
a40ef42ed6
|
@ -19,7 +19,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{Direction, InsertState, Mode, State};
|
||||
use crate::{Direction, InsertState, Mode, NormalState, State};
|
||||
|
||||
pub type Action = fn(&mut State);
|
||||
|
||||
|
@ -55,6 +55,37 @@ pub fn move_line_up(state: &mut State) {
|
|||
state.move_cursor(Direction::Up);
|
||||
}
|
||||
|
||||
pub fn page_up(state: &mut State) {
|
||||
state.set_error("page_up is unimplemented");
|
||||
}
|
||||
|
||||
pub fn page_down(state: &mut State) {
|
||||
state.set_error("page_down is unimplemented");
|
||||
}
|
||||
|
||||
pub fn goto_line_start(state: &mut State) {
|
||||
state.set_error("goto_line_start is unimplemented");
|
||||
}
|
||||
|
||||
pub fn goto_line_end_newline(state: &mut State) {
|
||||
state.set_error("goto_line_end_newline is unimplemented");
|
||||
}
|
||||
|
||||
pub fn normal_mode(state: &mut State) {
|
||||
match state.mode {
|
||||
Mode::Insert(InsertState { append: true }) => {
|
||||
state.move_cursor(Direction::Left);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
state.mode = Mode::Normal(NormalState::default());
|
||||
}
|
||||
|
||||
pub fn visual_mode(state: &mut State) {
|
||||
state.mode = Mode::Visual;
|
||||
}
|
||||
|
||||
pub fn insert_mode(state: &mut State) {
|
||||
state.mode = Mode::Insert(InsertState { append: false });
|
||||
}
|
||||
|
@ -63,6 +94,14 @@ pub fn append_mode(state: &mut State) {
|
|||
state.mode = Mode::Insert(InsertState { append: true });
|
||||
}
|
||||
|
||||
pub fn insert_at_line_start(state: &mut State) {
|
||||
state.set_error("insert_at_line_start is unimplemented");
|
||||
}
|
||||
|
||||
pub fn insert_at_line_end(state: &mut State) {
|
||||
state.set_error("insert_at_line_end is unimplemented");
|
||||
}
|
||||
|
||||
pub fn open_below(state: &mut State) {
|
||||
state.cursor.line += 1;
|
||||
state.cursor.column = 0;
|
||||
|
@ -75,3 +114,26 @@ pub fn open_above(state: &mut State) {
|
|||
state.buffer.insert_char(state.cursor, '\n');
|
||||
state.mode = Mode::Insert(InsertState { append: false });
|
||||
}
|
||||
|
||||
pub fn undo(state: &mut State) {
|
||||
state.set_error("undo is unimplemented");
|
||||
}
|
||||
|
||||
pub fn redo(state: &mut State) {
|
||||
state.set_error("redo is unimplemented");
|
||||
}
|
||||
|
||||
pub fn delete_char_backward(state: &mut State) {
|
||||
state.move_cursor(Direction::Left);
|
||||
state.buffer.remove(state.cursor);
|
||||
}
|
||||
|
||||
pub fn delete_char_forward(state: &mut State) {
|
||||
state.buffer.remove(state.cursor);
|
||||
}
|
||||
|
||||
pub fn insert_newline(state: &mut State) {
|
||||
state.buffer.insert_char(state.cursor, '\n');
|
||||
state.cursor.line += 1;
|
||||
state.cursor.column = 0;
|
||||
}
|
||||
|
|
|
@ -192,6 +192,13 @@ impl State {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the state to `Mode::Normal` with an error message.
|
||||
pub fn set_error(&mut self, error: impl ToString) {
|
||||
self.mode = Mode::Normal(NormalState {
|
||||
error: Some(error.to_string()),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_event(&mut self, event: Event) {
|
||||
match &self.mode {
|
||||
Mode::Normal(state) => self.on_normal_event(event, state.clone()),
|
||||
|
|
Reference in New Issue