diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-12 19:00:24 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-12 19:00:24 +0100 |
| commit | 123ba3b46acd16d420b82d5a25c5a4c50135afe6 (patch) | |
| tree | 7199741670cfcc43debc665fa243d6fb1ec37f5b /lib/editorBuffer.ml | |
| parent | d096051f807441d8a55d44ae55ee1f9463d6d808 (diff) | |
| download | sandy-123ba3b46acd16d420b82d5a25c5a4c50135afe6.tar.gz sandy-123ba3b46acd16d420b82d5a25c5a4c50135afe6.zip | |
feat: add support for "instant" normal commands (like [J]oin)
Diffstat (limited to 'lib/editorBuffer.ml')
| -rw-r--r-- | lib/editorBuffer.ml | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/editorBuffer.ml b/lib/editorBuffer.ml index b682116..ea89fb9 100644 --- a/lib/editorBuffer.ml +++ b/lib/editorBuffer.ml | |||
| @@ -29,13 +29,12 @@ module Action = struct | |||
| 29 | let bof = far_left |> on_content | 29 | let bof = far_left |> on_content |
| 30 | let eof = far_right |> on_content | 30 | let eof = far_right |> on_content |
| 31 | let insert k = map_focus (push k) |> on_content | 31 | let insert k = map_focus (push k) |> on_content |
| 32 | (* let replace k = () *) | ||
| 32 | 33 | ||
| 33 | let delete_after ?(cross_lines = false) ~n = | 34 | let delete_after ?(cross_lines = false) ~n = |
| 34 | let aux z = | 35 | let aux z = |
| 35 | let line = focus_or ~default:Zipper.empty z in | 36 | let line = focus_or ~default:Zipper.empty z in |
| 36 | if cross_lines && is_far_right line && not (is_far_right z) then | 37 | if cross_lines && is_far_right line && not (is_far_right z) then |
| 37 | (* let next = right z |> focus_or ~default:Zipper.empty |> far_left in *) | ||
| 38 | (* right z |> pop_after |> left |> map_focus (Fn.flip join next) *) | ||
| 39 | pop_after z |> map_focus_or ~default:line (far_left &> join line) | 38 | pop_after z |> map_focus_or ~default:line (far_left &> join line) |
| 40 | else map_focus pop_after z | 39 | else map_focus pop_after z |
| 41 | in | 40 | in |
| @@ -53,9 +52,7 @@ module Action = struct | |||
| 53 | let delete_to_eol = map_focus (split &> fst) |> on_content | 52 | let delete_to_eol = map_focus (split &> fst) |> on_content |
| 54 | let delete_to_bol = map_focus (split &> snd) |> on_content | 53 | let delete_to_bol = map_focus (split &> snd) |> on_content |
| 55 | let delete_lines ~n = Fn.apply_n_times ~n pop_after |> on_content | 54 | let delete_lines ~n = Fn.apply_n_times ~n pop_after |> on_content |
| 56 | 55 | let delete_lines_before ~n = Fn.apply_n_times ~n pop_before |> on_content | |
| 57 | let delete_lines_before ~n = | ||
| 58 | on_content (fun z -> pop_after z |> Fn.apply_n_times ~n:(n - 1) pop_before) | ||
| 59 | 56 | ||
| 60 | let newline = | 57 | let newline = |
| 61 | let aux z = | 58 | let aux z = |
| @@ -64,6 +61,15 @@ module Action = struct | |||
| 64 | in | 61 | in |
| 65 | on_content aux | 62 | on_content aux |
| 66 | 63 | ||
| 64 | let join_lines ~n = | ||
| 65 | let aux z = | ||
| 66 | if is_far_right z || is_far_right (right z) then z | ||
| 67 | else | ||
| 68 | let line = focus_or ~default:Zipper.empty z |> far_right in | ||
| 69 | pop_after z |> map_focus (far_left &> join line) | ||
| 70 | in | ||
| 71 | Fn.apply_n_times ~n aux |> on_content | ||
| 72 | |||
| 67 | (* let save_history_to ?(clear = true) r = () *) | 73 | (* let save_history_to ?(clear = true) r = () *) |
| 68 | end | 74 | end |
| 69 | 75 | ||
