From: Michael D. Lowis Date: Sat, 20 Jan 2018 02:22:58 +0000 (-0500) Subject: can now move cursor around by clicking X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=854e95fb82e0fef6df13a23602bee64e22558308;p=archive%2Ftide-ocaml.git can now move cursor around by clicking --- 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