From: Michael D. Lowis Date: Thu, 25 Jan 2018 19:19:57 +0000 (-0500) Subject: updated cursor logic to allow selecting ranges of cursors with the mouse X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=7d6abade8fd6b9064be2d9a1007a738ca7a117cf;p=archive%2Ftide-ocaml.git updated cursor logic to allow selecting ranges of cursors with the mouse --- diff --git a/edit.ml b/edit.ml index 1c101da..a7cfdd6 100644 --- 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 diff --git a/lib/buf.ml b/lib/buf.ml index 39f1cba..401e409 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -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 = diff --git a/lib/buf.mli b/lib/buf.mli index 74c7823..91f1d3c 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -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 diff --git a/lib/view.ml b/lib/view.ml index 4a53186..e2026be 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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