From dd936fc7d2e0a31594b7ef17063c964d2f0a1c5d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 6 Nov 2017 21:00:19 -0500 Subject: [PATCH] reworked index manipulation for next and previous lines into rope.ml. Still need a more abstracted and efficient interface --- docs/Rope.html | 4 +++- docs/index_values.html | 4 ++++ lib/rope.ml | 16 ++++++++-------- lib/rope.mli | 2 ++ lib/scrollmap.ml | 14 +++++--------- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/Rope.html b/docs/Rope.html index 6110fe7..8b12eb3 100644 --- a/docs/Rope.html +++ b/docs/Rope.html @@ -80,4 +80,6 @@
val is_eol : t -> int -> bool
val move_till : int -> (t -> int -> bool) -> t -> int -> int
val to_bol : t -> int -> int
-
val to_eol : t -> int -> int
\ No newline at end of file +
val to_eol : t -> int -> int
+
val nextln : t -> int -> int
+
val prevln : t -> int -> int
\ No newline at end of file diff --git a/docs/index_values.html b/docs/index_values.html index 157b6bb..c5f3910 100644 --- a/docs/index_values.html +++ b/docs/index_values.html @@ -214,6 +214,8 @@ nextc [Rope] +nextln [Rope] + normal [Cfg.Color.Syntax] number [Cfg.Color.Syntax] @@ -230,6 +232,8 @@ prevc [Rope] +prevln [Rope] + procedure [Cfg.Color.Syntax] prop_get [X11] diff --git a/lib/rope.ml b/lib/rope.ml index 5c078db..fdde27f 100644 --- a/lib/rope.ml +++ b/lib/rope.ml @@ -46,14 +46,6 @@ let join left right = let nh = 1 + lh + rh in Node (left, right, nh, llen + rlen) -(* - let n = Node (left, right, nh, llen + rlen) in - match (lh - rh) with - | 0 -> n - | 1 -> n - | -1 -> n -*) - let rec split rope i = if i < 0 || i > (length rope) then raise (Out_of_bounds "Rope.split"); @@ -172,3 +164,11 @@ let to_bol rope pos = let to_eol rope pos = move_till (+1) is_eol rope pos + +(******************************************************************************) + +let nextln rope pos = + nextc rope (to_eol rope pos) + +let prevln rope pos = + prevc rope (to_bol rope pos) diff --git a/lib/rope.mli b/lib/rope.mli index 227323b..69a5591 100644 --- a/lib/rope.mli +++ b/lib/rope.mli @@ -30,6 +30,8 @@ val puts : rope -> string -> int -> rope val nextc : rope -> int -> int val prevc : rope -> int -> int +val nextln : rope -> int -> int +val prevln : rope -> int -> int val is_bol : rope -> int -> bool val is_eol : rope -> int -> bool diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index 8a8fefe..7f8682d 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -15,10 +15,10 @@ let make buf width off = let bol = (Rope.to_bol (Buf.rope buf) off) in let lines = ref [bol] in let process_glyph i c = - let is_eol = (Rope.is_eol (Buf.rope buf) i) in - if (Draw.Cursor.next_glyph csr c) && is_eol == false then + let not_eol = ((Rope.is_eol (Buf.rope buf) i) == false) in + if (Draw.Cursor.next_glyph csr c) && not_eol then lines := i :: !lines; - (is_eol == false) + not_eol in Buf.iteri_from process_glyph buf off; let lines = (Array.of_list (List.rev !lines)) in @@ -28,13 +28,9 @@ let make buf width off = let first map = map.lines.(map.index) -let bopl buf off = - let rope = (Buf.rope buf) in - Rope.prevc rope (Rope.to_bol rope off) +let bopl buf off = (Rope.prevln (Buf.rope buf) off) -let bonl buf off = - let rope = (Buf.rope buf) in - Rope.nextc rope (Rope.to_eol rope off) +let bonl buf off = (Rope.nextln (Buf.rope buf) off) let scroll_up map buf = let next = map.index - 1 in -- 2.52.0