aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-06-07 15:15:39 +0000
committerBlaž Hrastnik2020-06-07 15:15:39 +0000
commite98cdebf1eb6ea5233c0d4cb0ae84c251fdae987 (patch)
tree0a9f757667714f2b0210d7dc183a1544150af3ff /helix-core/src/commands.rs
parent195aad4675d62ab6d74b59990422b27d95ab85c7 (diff)
Add a command module.
Diffstat (limited to 'helix-core/src/commands.rs')
-rw-r--r--helix-core/src/commands.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/helix-core/src/commands.rs b/helix-core/src/commands.rs
new file mode 100644
index 00000000..78a1481a
--- /dev/null
+++ b/helix-core/src/commands.rs
@@ -0,0 +1,45 @@
+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).
+type Command = fn(state: &mut State, count: usize);
+
+fn move_char_left(state: &mut State, count: usize) {
+ // TODO: use a transaction
+ state.selection = state.move_selection(
+ state.selection,
+ Direction::Backward,
+ Granularity::Character,
+ count,
+ );
+}
+
+fn move_char_right(state: &mut State, count: usize) {
+ // TODO: use a transaction
+ state.selection = state.move_selection(
+ state.selection,
+ Direction::Forward,
+ Granularity::Character,
+ count,
+ );
+}
+
+fn move_line_up(state: &mut State, count: usize) {
+ // TODO: use a transaction
+ state.selection = state.move_selection(
+ state.selection,
+ Direction::Backward,
+ Granularity::Line,
+ count,
+ );
+}
+
+fn move_line_down(state: &mut State, count: usize) {
+ // TODO: use a transaction
+ state.selection = state.move_selection(
+ state.selection,
+ Direction::Forward,
+ Granularity::Line,
+ count,
+ );
+}