From f5c33507a74d83692c028d1e1659d3506399138e Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 28 Jan 2024 23:42:12 +0100 Subject: feat: add non-linear change history with undo/redo --- lib/command.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/command.ml') diff --git a/lib/command.ml b/lib/command.ml index 2d7b51b..6439165 100644 --- a/lib/command.ml +++ b/lib/command.ml @@ -17,6 +17,10 @@ type operation = | Search | Search_rev | Goto + | Undo + | Redo + | Earlier + | Later type scope = Line | To_bol | To_eol | Down | Left | Right | Up @@ -85,6 +89,8 @@ let instant_operation = Key 'X'; Key 'p'; Key 'x'; + Key 'u'; + Ctrl 'R'; ] let chord_operation = [ Key 'c'; Key 'd'; Key 'y' ] @@ -101,6 +107,8 @@ let to_op = function | Key 'P' -> Paste_before | Key 'x' -> Erase_after | Key 'X' -> Erase_before + | Key 'u' -> Undo + | Ctrl 'R' -> Redo | _ -> failwith "Invalid operation in chord." let is_chord_operation k = List.mem ~equal:Poly.equal chord_operation k @@ -129,6 +137,15 @@ let n_stream = (`start, shortcut ~r (to_op k)) | `chord_fst_n (r, n), k when is_instant_operation k -> (`start, shortcut ?r ~n (to_op k)) + (* Special operations *) + | `start, Key 'g' -> (`special (None, None), Partial k) + | `chord_reg r, Key 'g' -> (`special (Some r, None), Partial k) + | `chord_fst_n (r, n), Key 'g' -> (`special (r, Some n), Partial k) + | `special (r, n), Key 'g' -> + let n = Option.value ~default:0 n in + (`start, shortcut ?r ~n Goto) + | `special (r, n), Key '-' -> (`start, shortcut ?r ?n Earlier) + | `special (r, n), Key '+' -> (`start, shortcut ?r ?n Later) (* Chord operation (first) *) | `start, k when is_chord_operation k -> (`chord_cmd (None, None, to_op k), Partial k) -- cgit v1.2.3