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/editor.ml | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'lib/editor.ml') 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 = | Chord (_, n, Noop, _, Right) -> Buffer.Action.move_right ?n |> on_focused_buffer | Chord (_, n, Noop, _, Up) -> Buffer.Action.move_up ?n |> on_focused_buffer - | Simple (Ctrl 'Q') -> quit 0 - (* | Key '0' -> Buffer.Action.bol |> on_focused_buffer_or_new *) - | Simple (Key 'A') -> - (Buffer.Action.eol |> on_focused_buffer_or_new) *> set_mode Insert - | Simple (Key 'a') -> - (Buffer.Action.move_right |> on_focused_buffer_or_new) *> set_mode Insert - (* | Key 'G' -> Buffer.Action.eof |> on_focused_buffer_or_new *) - (* | Key 'I' -> noop *) - | Simple (Key 'i') -> (Fn.id |> on_focused_buffer_or_new) *> set_mode Insert - (* | Key 's' -> *) - (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) - (* *> set_mode Insert *) - (* | Key 'x' | Delete -> Buffer.Action.delete_after |> on_focused_buffer_or_new *) - (* | Key 'X' -> Buffer.Action.delete_before |> on_focused_buffer_or_new *) - (* | Key '$' -> Buffer.Action.eol |> on_focused_buffer_or_new *) + | Chord (_, n, Noop, _, To_bol) -> + let n = Option.value ~default:1 n - 1 in + Buffer.Action.(move_down ~n &> bol) |> on_focused_buffer + | Chord (_, n, Noop, _, To_eol) -> + let n = Option.value ~default:1 n - 1 in + Buffer.Action.(move_down ~n &> eol) |> on_focused_buffer (* Change *) | Shortcut (_, n, Change) -> let n = Option.value ~default:1 n - 1 in @@ -258,6 +249,18 @@ let handle_normal_command = (Buffer.Action.(bol &> delete_to_eol &> delete_lines_before ~n) |> on_focused_buffer_or_new) *> set_mode Insert + | Chord (_, n1, Change, n2, To_bol) -> + let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in + (Buffer.Action.( + delete_to_bol &> move_down &> delete_lines ~n &> move_up &> bol) + |> on_focused_buffer_or_new) + *> set_mode Insert + | Chord (_, n1, Change, n2, To_eol) -> + let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in + (Buffer.Action.( + delete_to_eol &> move_down &> delete_lines ~n &> move_up &> eol) + |> on_focused_buffer_or_new) + *> set_mode Insert (* Delete *) | Shortcut (_, n, Delete) -> let n = Option.value ~default:1 n - 1 in @@ -286,10 +289,33 @@ let handle_normal_command = let n = Option.(value ~default:1 n1 * value ~default:1 n2) in Buffer.Action.(delete_lines ~n:1 &> delete_lines_before ~n) |> on_focused_buffer_or_new + | Chord (_, n1, Delete, n2, To_bol) -> + let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in + Buffer.Action.( + delete_to_bol &> move_down &> delete_lines ~n &> move_up &> bol) + |> on_focused_buffer_or_new + | Chord (_, n1, Delete, n2, To_eol) -> + let n = Option.((value ~default:1 n1 * value ~default:1 n2) - 1) in + Buffer.Action.( + delete_to_eol &> move_down &> delete_lines ~n &> move_up &> eol) + |> on_focused_buffer_or_new (* Join *) | Shortcut (_, n, Join) -> let n = Option.(value ~default:1 n) in Buffer.Action.join_lines ~n |> on_focused_buffer_or_new + (* Quit *) + | Simple (Ctrl 'Q') -> quit 0 + (* Misc *) + | Simple (Key 'A') -> + (Buffer.Action.eol |> on_focused_buffer_or_new) *> set_mode Insert + | Simple (Key 'a') -> + (Buffer.Action.move_right |> on_focused_buffer_or_new) *> set_mode Insert + (* | Key 'G' -> Buffer.Action.eof |> on_focused_buffer_or_new *) + (* | Key 'I' -> noop *) + | Simple (Key 'i') -> (Fn.id |> on_focused_buffer_or_new) *> set_mode Insert + (* | Key 's' -> *) + (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) + (* *> set_mode Insert *) | _ -> noop let handle_next_command m e = -- cgit v1.2.3