|
|
@ -2,42 +2,47 @@ 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
|
|
|
|
/// 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).
|
|
|
|
/// state (usually by creating and applying a transaction).
|
|
|
|
type Command = fn(state: &mut State, count: usize);
|
|
|
|
pub type Command = fn(state: &mut State, count: usize);
|
|
|
|
|
|
|
|
|
|
|
|
fn move_char_left(state: &mut State, count: usize) {
|
|
|
|
pub fn move_char_left(state: &mut State, count: usize) {
|
|
|
|
// TODO: use a transaction
|
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
let selection = state.move_selection(
|
|
|
|
state.selection,
|
|
|
|
// TODO: remove the clone here
|
|
|
|
|
|
|
|
state.selection.clone(),
|
|
|
|
Direction::Backward,
|
|
|
|
Direction::Backward,
|
|
|
|
Granularity::Character,
|
|
|
|
Granularity::Character,
|
|
|
|
count,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
state.selection = selection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_char_right(state: &mut State, count: usize) {
|
|
|
|
pub fn move_char_right(state: &mut State, count: usize) {
|
|
|
|
// TODO: use a transaction
|
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection,
|
|
|
|
// TODO: remove the clone here
|
|
|
|
|
|
|
|
state.selection.clone(),
|
|
|
|
Direction::Forward,
|
|
|
|
Direction::Forward,
|
|
|
|
Granularity::Character,
|
|
|
|
Granularity::Character,
|
|
|
|
count,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_up(state: &mut State, count: usize) {
|
|
|
|
pub fn move_line_up(state: &mut State, count: usize) {
|
|
|
|
// TODO: use a transaction
|
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection,
|
|
|
|
// TODO: remove the clone here
|
|
|
|
|
|
|
|
state.selection.clone(),
|
|
|
|
Direction::Backward,
|
|
|
|
Direction::Backward,
|
|
|
|
Granularity::Line,
|
|
|
|
Granularity::Line,
|
|
|
|
count,
|
|
|
|
count,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn move_line_down(state: &mut State, count: usize) {
|
|
|
|
pub fn move_line_down(state: &mut State, count: usize) {
|
|
|
|
// TODO: use a transaction
|
|
|
|
// TODO: use a transaction
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection = state.move_selection(
|
|
|
|
state.selection,
|
|
|
|
// TODO: remove the clone here
|
|
|
|
|
|
|
|
state.selection.clone(),
|
|
|
|
Direction::Forward,
|
|
|
|
Direction::Forward,
|
|
|
|
Granularity::Line,
|
|
|
|
Granularity::Line,
|
|
|
|
count,
|
|
|
|
count,
|
|
|
|