From 6563ec106879b76e1b1e6fdfabf33587cefa9dc0 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Fri, 12 Jan 2024 22:26:12 +0100 Subject: feat: add '0' and '$' movements --- lib/command.ml | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'lib/command.ml') diff --git a/lib/command.ml b/lib/command.ml index 97c1fdf..a68c723 100644 --- a/lib/command.ml +++ b/lib/command.ml @@ -41,11 +41,13 @@ let i_stream = let simple_movements = [ + Key ' '; + Key '0'; Key 'h'; Key 'j'; Key 'k'; Key 'l'; - Key ' '; + Key '$'; Arrow_up; Arrow_down; Arrow_left; @@ -53,37 +55,39 @@ let simple_movements = Backspace; ] -let instant_operation = - [ Key 'C'; Key 'D'; Key 'J'; Key 'P'; Key 'X'; Key 'p'; Key 'x' ] - -let chord_operation = [ Key 'c'; Key 'd'; Key 'y' ] - let to_scope = function | Key 'j' | Arrow_down -> Down | Key 'h' | Arrow_left | Backspace -> Left | Key 'l' | Key ' ' | Arrow_right -> Right | Key 'k' | Arrow_up -> Up + | Key '0' -> To_bol + | Key '$' -> To_eol | _ -> failwith "Invalid motion." +let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k + +let instant_operation = + [ Key 'C'; Key 'D'; Key 'J'; Key 'P'; Key 'X'; Key 'p'; Key 'x' ] + +let chord_operation = [ Key 'c'; Key 'd'; Key 'y' ] + +let to_op = function + | Key 'J' -> Join + | Key 'c' | Key 'C' -> Change + | Key 'd' | Key 'D' -> Delete + | Key 'y' | Key 'Y' -> Yank + | Key 'p' -> Paste_after + | Key 'P' -> Paste_before + | Key 'x' -> Erase_after + | Key 'X' -> Erase_before + | _ -> failwith "Invalid operation in chord." + +let is_chord_operation k = List.mem ~equal:Poly.equal chord_operation k +let is_instant_operation k = List.mem ~equal:Poly.equal instant_operation k + let n_stream = let step s k = let open Sequence.Step in - let is_chord_operation k = List.mem ~equal:Poly.equal chord_operation k in - let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k in - let is_instant_operation k = - List.mem ~equal:Poly.equal instant_operation k - in - let to_op = function - | Key 'J' -> Join - | Key 'c' | Key 'C' -> Change - | Key 'd' | Key 'D' -> Delete - | Key 'y' | Key 'Y' -> Yank - | Key 'p' -> Paste_after - | Key 'P' -> Paste_before - | Key 'x' -> Erase_after - | Key 'X' -> Erase_before - | _ -> failwith "Invalid operation in chord." - in match (s, k) with | `start, Key '"' -> Yield { value = Partial k; state = `chord_reg_pre } (* Register *) -- cgit v1.2.3