From af0cd851fec5038faff5a8133cadad6c65568374 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Wed, 24 Jan 2024 21:14:11 +0100 Subject: feat: add ability to paste text from a register Register are simplier than Vim register, in particular no register is local to buffers. --- lib/zipper.ml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/zipper.ml') 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 = if right_length z < 2 then z else right z |> pop ~n |> left let push x z = { z with after = Sequence.shift_right z.after x } +let push_seq s z = { z with after = Sequence.append s z.after } let push_after x z = right z |> push x |> left +let push_after_seq s z = right z |> push_seq s |> left let push_before x z = { z with pos = z.pos + 1; before = Sequence.shift_right z.before x } +let push_before_seq s z = + let f a e = Sequence.shift_right a e in + { + z with + pos = z.pos + Sequence.length s; + before = Sequence.fold ~init:z.before ~f s; + } + let split z = ( { z with after = Sequence.empty }, { z with pos = 0; before = Sequence.empty } ) @@ -119,7 +129,7 @@ let filter p z = z |> filter_left p |> filter_right p let context_left n z = { z with before = Sequence.take z.before n } let context_right n z = { z with after = Sequence.take z.after n } let context ~l ?(r = l) z = z |> context_left l |> context_right r -let swap_focus a = map_focus (Fn.const a) +let swap_focus a = map_focus_or ~default:a (Fn.const a) let of_seq s = { empty with after = s } let to_seq z = z |> far_left |> after let window ~from ~len z = goto from z |> context_right len |> after -- cgit v1.2.3