diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-12 22:26:12 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-12 22:26:12 +0100 |
| commit | 6563ec106879b76e1b1e6fdfabf33587cefa9dc0 (patch) | |
| tree | e4c775888d2f56209b527fae615ce6670eb36b27 /lib | |
| parent | 123ba3b46acd16d420b82d5a25c5a4c50135afe6 (diff) | |
| download | sandy-6563ec106879b76e1b1e6fdfabf33587cefa9dc0.tar.gz sandy-6563ec106879b76e1b1e6fdfabf33587cefa9dc0.zip | |
feat: add '0' and '$' movements
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.ml | 48 | ||||
| -rw-r--r-- | lib/editor.ml | 56 |
2 files changed, 67 insertions, 37 deletions
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 = | |||
| 41 | 41 | ||
| 42 | let simple_movements = | 42 | let simple_movements = |
| 43 | [ | 43 | [ |
| 44 | Key ' '; | ||
| 45 | Key '0'; | ||
| 44 | Key 'h'; | 46 | Key 'h'; |
| 45 | Key 'j'; | 47 | Key 'j'; |
| 46 | Key 'k'; | 48 | Key 'k'; |
| 47 | Key 'l'; | 49 | Key 'l'; |
| 48 | Key ' '; | 50 | Key '$'; |
| 49 | Arrow_up; | 51 | Arrow_up; |
| 50 | Arrow_down; | 52 | Arrow_down; |
| 51 | Arrow_left; | 53 | Arrow_left; |
| @@ -53,37 +55,39 @@ let simple_movements = | |||
| 53 | Backspace; | 55 | Backspace; |
| 54 | ] | 56 | ] |
| 55 | 57 | ||
| 56 | let instant_operation = | ||
| 57 | [ Key 'C'; Key 'D'; Key 'J'; Key 'P'; Key 'X'; Key 'p'; Key 'x' ] | ||
| 58 | |||
| 59 | let chord_operation = [ Key 'c'; Key 'd'; Key 'y' ] | ||
| 60 | |||
| 61 | let to_scope = function | 58 | let to_scope = function |
| 62 | | Key 'j' | Arrow_down -> Down | 59 | | Key 'j' | Arrow_down -> Down |
| 63 | | Key 'h' | Arrow_left | Backspace -> Left | 60 | | Key 'h' | Arrow_left | Backspace -> Left |
| 64 | | Key 'l' | Key ' ' | Arrow_right -> Right | 61 | | Key 'l' | Key ' ' | Arrow_right -> Right |
| 65 | | Key 'k' | Arrow_up -> Up | 62 | | Key 'k' | Arrow_up -> Up |
| 63 | | Key '0' -> To_bol | ||
| 64 | | Key '$' -> To_eol | ||
| 66 | | _ -> failwith "Invalid motion." | 65 | | _ -> failwith "Invalid motion." |
| 67 | 66 | ||
| 67 | let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k | ||
| 68 | |||
| 69 | let instant_operation = | ||
| 70 | [ Key 'C'; Key 'D'; Key 'J'; Key 'P'; Key 'X'; Key 'p'; Key 'x' ] | ||
| 71 | |||
| 72 | let chord_operation = [ Key 'c'; Key 'd'; Key 'y' ] | ||
| 73 | |||
| 74 | let to_op = function | ||
| 75 | | Key 'J' -> Join | ||
| 76 | | Key 'c' | Key 'C' -> Change | ||
| 77 | | Key 'd' | Key 'D' -> Delete | ||
| 78 | | Key 'y' | Key 'Y' -> Yank | ||
| 79 | | Key 'p' -> Paste_after | ||
| 80 | | Key 'P' -> Paste_before | ||
| 81 | | Key 'x' -> Erase_after | ||
| 82 | | Key 'X' -> Erase_before | ||
| 83 | | _ -> failwith "Invalid operation in chord." | ||
| 84 | |||
| 85 | let is_chord_operation k = List.mem ~equal:Poly.equal chord_operation k | ||
| 86 | let is_instant_operation k = List.mem ~equal:Poly.equal instant_operation k | ||
| 87 | |||
| 68 | let n_stream = | 88 | let n_stream = |
| 69 | let step s k = | 89 | let step s k = |
| 70 | let open Sequence.Step in | 90 | let open Sequence.Step in |
| 71 | let is_chord_operation k = List.mem ~equal:Poly.equal chord_operation k in | ||
| 72 | let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k in | ||
| 73 | let is_instant_operation k = | ||
| 74 | List.mem ~equal:Poly.equal instant_operation k | ||
| 75 | in | ||
| 76 | let to_op = function | ||
| 77 | | Key 'J' -> Join | ||
| 78 | | Key 'c' | Key 'C' -> Change | ||
| 79 | | Key 'd' | Key 'D' -> Delete | ||
| 80 | | Key 'y' | Key 'Y' -> Yank | ||
| 81 | | Key 'p' -> Paste_after | ||
| 82 | | Key 'P' -> Paste_before | ||
| 83 | | Key 'x' -> Erase_after | ||
| 84 | | Key 'X' -> Erase_before | ||
| 85 | | _ -> failwith "Invalid operation in chord." | ||
| 86 | in | ||
| 87 | match (s, k) with | 91 | match (s, k) with |
| 88 | | `start, Key '"' -> Yield { value = Partial k; state = `chord_reg_pre } | 92 | | `start, Key '"' -> Yield { value = Partial k; state = `chord_reg_pre } |
| 89 | (* Register *) | 93 | (* Register *) |
diff --git a/lib/editor.ml b/lib/editor.ml index adc9994..96623f2 100644 --- a/lib/editor.ml +++ b/lib/editor.ml | |||
| @@ -213,21 +213,12 @@ let handle_normal_command = | |||
| 213 | | Chord (_, n, Noop, _, Right) -> | 213 | | Chord (_, n, Noop, _, Right) -> |
| 214 | Buffer.Action.move_right ?n |> on_focused_buffer | 214 | Buffer.Action.move_right ?n |> on_focused_buffer |
| 215 | | Chord (_, n, Noop, _, Up) -> Buffer.Action.move_up ?n |> on_focused_buffer | 215 | | Chord (_, n, Noop, _, Up) -> Buffer.Action.move_up ?n |> on_focused_buffer |
| 216 | | Simple (Ctrl 'Q') -> quit 0 | 216 | | Chord (_, n, Noop, _, To_bol) -> |
| 217 | (* | Key '0' -> Buffer.Action.bol |> on_focused_buffer_or_new *) | 217 | let n = Option.value ~default:1 n - 1 in |
| 218 | | Simple (Key 'A') -> | 218 | Buffer.Action.(move_down ~n &> bol) |> on_focused_buffer |
| 219 | (Buffer.Action.eol |> on_focused_buffer_or_new) *> set_mode Insert | 219 | | Chord (_, n, Noop, _, To_eol) -> |
| 220 | | Simple (Key 'a') -> | 220 | let n = Option.value ~default:1 n - 1 in |
| 221 | (Buffer.Action.move_right |> on_focused_buffer_or_new) *> set_mode Insert | 221 | Buffer.Action.(move_down ~n &> eol) |> on_focused_buffer |
| 222 | (* | Key 'G' -> Buffer.Action.eof |> on_focused_buffer_or_new *) | ||
| 223 | (* | Key 'I' -> noop *) | ||
| 224 | | Simple (Key 'i') -> (Fn.id |> on_focused_buffer_or_new) *> set_mode Insert | ||
| 225 | (* | Key 's' -> *) | ||
| 226 | (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) | ||
| 227 | (* *> set_mode Insert *) | ||
| 228 | (* | Key 'x' | Delete -> Buffer.Action.delete_after |> on_focused_buffer_or_new *) | ||
| 229 | (* | Key 'X' -> Buffer.Action.delete_before |> on_focused_buffer_or_new *) | ||
| 230 | (* | Key '$' -> Buffer.Action.eol |> on_focused_buffer_or_new *) | ||
| 231 | (* Change *) | 222 | (* Change *) |
| 232 | | Shortcut (_, n, Change) -> | 223 | | Shortcut (_, n, Change) -> |
| 233 | let n = Option.value ~default:1 n - 1 in | 224 | let n = Option.value ~default:1 n - 1 in |
| @@ -258,6 +249,18 @@ let handle_normal_command = | |||
| 258 | (Buffer.Action.(bol &> delete_to_eol &> delete_lines_before ~n) | 249 | (Buffer.Action.(bol &> delete_to_eol &> delete_lines_before ~n) |
| 259 | |> on_focused_buffer_or_new) | 250 | |> on_focused_buffer_or_new) |
| 260 | *> set_mode Insert | 251 | *> set_mode Insert |
| 252 | | Chord (_, n1, Change, n2, To_bol) -> | ||
| 253 | let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in | ||
| 254 | (Buffer.Action.( | ||
| 255 | delete_to_bol &> move_down &> delete_lines ~n &> move_up &> bol) | ||
| 256 | |> on_focused_buffer_or_new) | ||
| 257 | *> set_mode Insert | ||
| 258 | | Chord (_, n1, Change, n2, To_eol) -> | ||
| 259 | let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in | ||
| 260 | (Buffer.Action.( | ||
| 261 | delete_to_eol &> move_down &> delete_lines ~n &> move_up &> eol) | ||
| 262 | |> on_focused_buffer_or_new) | ||
| 263 | *> set_mode Insert | ||
| 261 | (* Delete *) | 264 | (* Delete *) |
| 262 | | Shortcut (_, n, Delete) -> | 265 | | Shortcut (_, n, Delete) -> |
| 263 | let n = Option.value ~default:1 n - 1 in | 266 | let n = Option.value ~default:1 n - 1 in |
| @@ -286,10 +289,33 @@ let handle_normal_command = | |||
| 286 | let n = Option.(value ~default:1 n1 * value ~default:1 n2) in | 289 | let n = Option.(value ~default:1 n1 * value ~default:1 n2) in |
| 287 | Buffer.Action.(delete_lines ~n:1 &> delete_lines_before ~n) | 290 | Buffer.Action.(delete_lines ~n:1 &> delete_lines_before ~n) |
| 288 | |> on_focused_buffer_or_new | 291 | |> on_focused_buffer_or_new |
| 292 | | Chord (_, n1, Delete, n2, To_bol) -> | ||
| 293 | let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in | ||
| 294 | Buffer.Action.( | ||
| 295 | delete_to_bol &> move_down &> delete_lines ~n &> move_up &> bol) | ||
| 296 | |> on_focused_buffer_or_new | ||
| 297 | | Chord (_, n1, Delete, n2, To_eol) -> | ||
| 298 | let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in | ||
| 299 | Buffer.Action.( | ||
| 300 | delete_to_eol &> move_down &> delete_lines ~n &> move_up &> eol) | ||
| 301 | |> on_focused_buffer_or_new | ||
| 289 | (* Join *) | 302 | (* Join *) |
| 290 | | Shortcut (_, n, Join) -> | 303 | | Shortcut (_, n, Join) -> |
| 291 | let n = Option.(value ~default:1 n) in | 304 | let n = Option.(value ~default:1 n) in |
| 292 | Buffer.Action.join_lines ~n |> on_focused_buffer_or_new | 305 | Buffer.Action.join_lines ~n |> on_focused_buffer_or_new |
| 306 | (* Quit *) | ||
| 307 | | Simple (Ctrl 'Q') -> quit 0 | ||
| 308 | (* Misc *) | ||
| 309 | | Simple (Key 'A') -> | ||
| 310 | (Buffer.Action.eol |> on_focused_buffer_or_new) *> set_mode Insert | ||
| 311 | | Simple (Key 'a') -> | ||
| 312 | (Buffer.Action.move_right |> on_focused_buffer_or_new) *> set_mode Insert | ||
| 313 | (* | Key 'G' -> Buffer.Action.eof |> on_focused_buffer_or_new *) | ||
| 314 | (* | Key 'I' -> noop *) | ||
| 315 | | Simple (Key 'i') -> (Fn.id |> on_focused_buffer_or_new) *> set_mode Insert | ||
| 316 | (* | Key 's' -> *) | ||
| 317 | (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) | ||
| 318 | (* *> set_mode Insert *) | ||
| 293 | | _ -> noop | 319 | | _ -> noop |
| 294 | 320 | ||
| 295 | let handle_next_command m e = | 321 | let handle_next_command m e = |
