diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-24 21:14:11 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-24 21:14:11 +0100 |
| commit | af0cd851fec5038faff5a8133cadad6c65568374 (patch) | |
| tree | 5f594f6140f6e070fb4a96b1ba4d937d7f43d1b7 /lib/zipper.ml | |
| parent | 7510a0194125ad6229fe8e84f436faa7f87b7c25 (diff) | |
| download | sandy-af0cd851fec5038faff5a8133cadad6c65568374.tar.gz sandy-af0cd851fec5038faff5a8133cadad6c65568374.zip | |
feat: add ability to paste text from a register
Register are simplier than Vim register, in particular no register is
local to buffers.
Diffstat (limited to 'lib/zipper.ml')
| -rw-r--r-- | lib/zipper.ml | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/zipper.ml b/lib/zipper.ml index 202f6d4..413f365 100644 --- a/lib/zipper.ml +++ b/lib/zipper.ml | |||
| @@ -61,11 +61,21 @@ let pop_after ?(n = 1) z = | |||
| 61 | if right_length z < 2 then z else right z |> pop ~n |> left | 61 | if right_length z < 2 then z else right z |> pop ~n |> left |
| 62 | 62 | ||
| 63 | let push x z = { z with after = Sequence.shift_right z.after x } | 63 | let push x z = { z with after = Sequence.shift_right z.after x } |
| 64 | let push_seq s z = { z with after = Sequence.append s z.after } | ||
| 64 | let push_after x z = right z |> push x |> left | 65 | let push_after x z = right z |> push x |> left |
| 66 | let push_after_seq s z = right z |> push_seq s |> left | ||
| 65 | 67 | ||
| 66 | let push_before x z = | 68 | let push_before x z = |
| 67 | { z with pos = z.pos + 1; before = Sequence.shift_right z.before x } | 69 | { z with pos = z.pos + 1; before = Sequence.shift_right z.before x } |
| 68 | 70 | ||
| 71 | let push_before_seq s z = | ||
| 72 | let f a e = Sequence.shift_right a e in | ||
| 73 | { | ||
| 74 | z with | ||
| 75 | pos = z.pos + Sequence.length s; | ||
| 76 | before = Sequence.fold ~init:z.before ~f s; | ||
| 77 | } | ||
| 78 | |||
| 69 | let split z = | 79 | let split z = |
| 70 | ( { z with after = Sequence.empty }, | 80 | ( { z with after = Sequence.empty }, |
| 71 | { z with pos = 0; before = Sequence.empty } ) | 81 | { z with pos = 0; before = Sequence.empty } ) |
| @@ -119,7 +129,7 @@ let filter p z = z |> filter_left p |> filter_right p | |||
| 119 | let context_left n z = { z with before = Sequence.take z.before n } | 129 | let context_left n z = { z with before = Sequence.take z.before n } |
| 120 | let context_right n z = { z with after = Sequence.take z.after n } | 130 | let context_right n z = { z with after = Sequence.take z.after n } |
| 121 | let context ~l ?(r = l) z = z |> context_left l |> context_right r | 131 | let context ~l ?(r = l) z = z |> context_left l |> context_right r |
| 122 | let swap_focus a = map_focus (Fn.const a) | 132 | let swap_focus a = map_focus_or ~default:a (Fn.const a) |
| 123 | let of_seq s = { empty with after = s } | 133 | let of_seq s = { empty with after = s } |
| 124 | let to_seq z = z |> far_left |> after | 134 | let to_seq z = z |> far_left |> after |
| 125 | let window ~from ~len z = goto from z |> context_right len |> after | 135 | let window ~from ~len z = goto from z |> context_right len |> after |
