]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
can now move cursor around by clicking
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 20 Jan 2018 02:22:58 +0000 (21:22 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 20 Jan 2018 02:22:58 +0000 (21:22 -0500)
edit.ml
lib/buf.ml
lib/buf.mli
lib/view.ml

diff --git a/edit.ml b/edit.ml
index ff6a713f2dbb65bee73bbc695b576ff6ec2d311e..1c101dade3ddc5d76279068bdb6d9b1f961f7c16 100644 (file)
--- 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;
index 4d80e1492b19001cb10b5e2c61514b82f0132cea..39f1cbaa32e44e986c787751c928297bb88107e4 100644 (file)
@@ -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 }
index db12bf0a7c9a34a7fbbcd18a893cb5c6ab1b971f..74c78234fc89e976a97c77398272e4417e9c90a2 100644 (file)
@@ -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
index 08c1070053857e6eded7b0897bcffcfc6e746e9d..c1e2dda899040b0124429eb4200648261875c7fb 100644 (file)
@@ -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