From ae2577585736aba642fcffc2a18cf6ef28a5a1ae Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 19 Dec 2017 22:16:02 -0500 Subject: [PATCH] added logic to determine if a drawn character is selected and tweaked cursor pos api --- lib/buf.ml | 12 ++++++------ lib/buf.mli | 4 +++- lib/draw.ml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/buf.ml b/lib/buf.ml index a3e48f1..08eda4c 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -52,7 +52,7 @@ module Cursor = struct csr let initial = - { start = 0; stop = 0 } + { start = 0; stop = 1 } let make buf idx = { start = 0; stop = (Rope.limit_index buf.rope idx) } @@ -82,7 +82,6 @@ let nextln = move_to NextLine let prevln = move_to PrevLine let bol = move_to StartOfLine - let pick_syntax path = let name = Filename.basename path in let ext = Filename.extension path in @@ -117,8 +116,11 @@ let iteri fn buf i = let iter fn buf i = iteri (fun i c -> (fn c)) buf i -let cursor buf = - buf.cursor +let csrpos buf = + Cursor.stop buf.cursor + +let selected buf pos = + Cursor.selected buf.cursor pos let make_lexer buf = let pos = ref 0 in @@ -176,5 +178,3 @@ let is_at dest buf i = let is_bol = is_at StartOfLine let is_eol = is_at EndOfLine *) - - diff --git a/lib/buf.mli b/lib/buf.mli index ced60f4..db12bf0 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -19,8 +19,10 @@ val path : t -> string val length : t -> int val iteri : (int -> int -> bool) -> t -> int -> unit val iter : (int -> bool) -> t -> int -> unit -val cursor : t -> Cursor.t +val csrpos : t -> int +val selected : t -> int -> bool val make_lexer : t -> Colormap.lexer + val nextln : t -> int -> int val prevln : t -> int -> int val bol : t -> int -> int diff --git a/lib/draw.ml b/lib/draw.ml index f5d6ea3..107e591 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -104,7 +104,7 @@ let buffer csr buf clr off = let num = ref 0 and csr = (restart csr 2 0) in let draw_rune c = let pos = off + !num in - if pos == (Buf.Cursor.stop (Buf.cursor buf)) then + if pos == (Buf.csrpos buf) then draw_cursor csr; draw_glyph csr c (Colormap.find pos clr); num := !num + 1; -- 2.52.0