]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
updated cursor logic to allow selecting ranges of cursors with the mouse
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 25 Jan 2018 19:19:57 +0000 (14:19 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 25 Jan 2018 19:19:57 +0000 (14:19 -0500)
edit.ml
lib/buf.ml
lib/buf.mli
lib/view.ml

diff --git a/edit.ml b/edit.ml
index 1c101dade3ddc5d76279068bdb6d9b1f961f7c16..a7cfdd6fb3b235f3d8b82198812d5d68ef001e20 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -16,8 +16,9 @@ let scroll_dn () =
 (* Mouse Actions
  ******************************************************************************)
 let onselect mods x y nclicks =
-  let pos = (View.get_at !edit_view x y) in
-  edit_view := View.select !edit_view pos pos
+  Printf.printf "select (%d,%d) %d" x y nclicks;
+  print_endline "";
+  edit_view := View.select !edit_view (View.get_at !edit_view x y)
 
 let onexec mods x y nclicks =
   Printf.printf "exec (%d,%d) %d" x y nclicks;
@@ -45,8 +46,9 @@ let onmousebtn mods btn x y pressed nclicks =
   | _ -> ()
 
 let onmousemove mods x y =
-  Printf.printf "click (%d,%d)" x y;
-  print_endline ""
+  Printf.printf "select (%d,%d)" x y;
+  print_endline "";
+  edit_view := View.select ~extend:true !edit_view (View.get_at !edit_view x y)
 
 let onupdate width height =
   let csr = Draw.Cursor.make (width, height) 0 0 in
index 39f1cbaa32e44e986c787751c928297bb88107e4..401e4091074548de2130b7449c9d4e30bd059de8 100644 (file)
@@ -52,10 +52,15 @@ module Cursor = struct
       csr
 
   let initial =
-    { start = 0; stop = 1 }
+    { start = 0; stop = 0 }
 
   let make buf idx =
-    { start = 0; stop = (Rope.limit_index buf.rope idx) }
+    let idx = (Rope.limit_index buf.rope idx) in
+    { start = idx; stop = idx }
+
+  let select buf start stop =
+    { start = (Rope.limit_index buf.rope start);
+      stop = (Rope.limit_index buf.rope stop) }
 
   let move_to dest buf csr =
     csr.stop <- (match dest with
@@ -119,6 +124,9 @@ let iter fn buf i =
 let csrpos buf =
   Cursor.stop buf.cursor
 
+let csrrange buf =
+  (buf.cursor.start, buf.cursor.stop)
+
 let selected buf pos =
   Cursor.selected buf.cursor pos
 
@@ -137,7 +145,9 @@ let make_lexer buf =
   })
 
 let select buf start stop =
-  { buf with cursor = Cursor.make buf start }
+  Printf.printf "Buf.select %d %d\n" start stop;
+  print_endline "";
+  { buf with cursor = Cursor.select buf start stop }
 
 (*
   let clone csr =
index 74c78234fc89e976a97c77398272e4417e9c90a2..91f1d3c962764191335df912176ce6ff9377477f 100644 (file)
@@ -20,6 +20,8 @@ val length : t -> int
 val iteri : (int -> int -> bool) -> t -> int -> unit
 val iter : (int -> bool) -> t -> int -> unit
 val csrpos : t -> int
+val csrrange : t -> (int * int)
+
 val selected : t -> int -> bool
 val make_lexer : t -> Colormap.lexer
 val select : t -> int -> int -> t
index 4a53186707e511e28db8620c46a0cf4841dd2e51..e2026beeedd2e529a0b296f48d24d9ad06d6d56c 100644 (file)
@@ -48,6 +48,14 @@ let get_at view x y =
 let select view start stop =
   { view with buf = Buf.select view.buf start stop }
 
+let select ?extend:(ext=false) view pos =
+  let start,stop = Buf.csrrange view.buf in
+  if ext then
+    { view with buf = Buf.select view.buf start pos }
+  else
+    { view with buf = Buf.select view.buf pos pos }
+
+
 let path view =
   Buf.path view.buf