2020-06-07 17:15:39 +02:00
|
|
|
use crate::state::{Direction, Granularity, State};
|
|
|
|
|
|
|
|
/// A command is a function that takes the current state and a count, and does a side-effect on the
|
|
|
|
/// state (usually by creating and applying a transaction).
|
2020-06-07 17:31:11 +02:00
|
|
|
pub type Command = fn(state: &mut State, count: usize);
|
2020-06-07 17:15:39 +02:00
|
|
|
|
2020-06-07 17:31:11 +02:00
|
|
|
pub fn move_char_left(state: &mut State, count: usize) {
|
2020-06-07 17:15:39 +02:00
|
|
|
// TODO: use a transaction
|
2020-06-07 17:31:11 +02:00
|
|
|
let selection = state.move_selection(
|
|
|
|
// TODO: remove the clone here
|
|
|
|
state.selection.clone(),
|
2020-06-07 17:15:39 +02:00
|
|
|
Direction::Backward,
|
|
|
|
Granularity::Character,
|
|
|
|
count,
|
|
|
|
);
|
2020-06-07 17:31:11 +02:00
|
|
|
state.selection = selection;
|
2020-06-07 17:15:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 17:31:11 +02:00
|
|
|
pub fn move_char_right(state: &mut State, count: usize) {
|
2020-06-07 17:15:39 +02:00
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
2020-06-07 17:31:11 +02:00
|
|
|
// TODO: remove the clone here
|
|
|
|
state.selection.clone(),
|
2020-06-07 17:15:39 +02:00
|
|
|
Direction::Forward,
|
|
|
|
Granularity::Character,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:31:11 +02:00
|
|
|
pub fn move_line_up(state: &mut State, count: usize) {
|
2020-06-07 17:15:39 +02:00
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
2020-06-07 17:31:11 +02:00
|
|
|
// TODO: remove the clone here
|
|
|
|
state.selection.clone(),
|
2020-06-07 17:15:39 +02:00
|
|
|
Direction::Backward,
|
|
|
|
Granularity::Line,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:31:11 +02:00
|
|
|
pub fn move_line_down(state: &mut State, count: usize) {
|
2020-06-07 17:15:39 +02:00
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
2020-06-07 17:31:11 +02:00
|
|
|
// TODO: remove the clone here
|
|
|
|
state.selection.clone(),
|
2020-06-07 17:15:39 +02:00
|
|
|
Direction::Forward,
|
|
|
|
Granularity::Line,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
}
|