From 854e95fb82e0fef6df13a23602bee64e22558308 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 19 Jan 2018 21:22:58 -0500 Subject: [PATCH] can now move cursor around by clicking --- edit.ml | 5 ++--- lib/buf.ml | 3 +++ lib/buf.mli | 1 + lib/view.ml | 8 ++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/edit.ml b/edit.ml index ff6a713..1c101da 100644 --- a/edit.ml +++ b/edit.ml @@ -16,9 +16,8 @@ let scroll_dn () = (* Mouse Actions ******************************************************************************) let onselect mods x y nclicks = - let sx,sy = !edit_view.pos and w,h = !edit_view.dim in - Printf.printf "select (%d,%d) %d" x y nclicks; - print_endline "" + let pos = (View.get_at !edit_view x y) in + edit_view := View.select !edit_view pos pos let onexec mods x y nclicks = Printf.printf "exec (%d,%d) %d" x y nclicks; diff --git a/lib/buf.ml b/lib/buf.ml index 4d80e14..39f1cba 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -136,6 +136,9 @@ let make_lexer buf = !count) }) +let select buf start stop = + { buf with cursor = Cursor.make buf start } + (* let clone csr = { start = csr.start; stop = csr.stop } diff --git a/lib/buf.mli b/lib/buf.mli index db12bf0..74c7823 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -22,6 +22,7 @@ val iter : (int -> bool) -> t -> int -> unit val csrpos : t -> int val selected : t -> int -> bool val make_lexer : t -> Colormap.lexer +val select : t -> int -> int -> t val nextln : t -> int -> int val prevln : t -> int -> int diff --git a/lib/view.ml b/lib/view.ml index 08c1070..c1e2dda 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -21,6 +21,14 @@ let empty width height = let make width height path = from_buffer (Buf.load path) width height +let get_at view x y = + let sx,sy = view.pos and w,h = view.dim in + try List.nth view.lines ((h - (y + 2)) / Draw.font.height) + with Failure _ -> Buf.length view.buf + +let select view start stop = + { view with buf = Buf.select view.buf start stop } + let path view = Buf.path view.buf -- 2.52.0