]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
added function to create a cursor
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 21 Oct 2017 17:42:18 +0000 (13:42 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 21 Oct 2017 17:42:18 +0000 (13:42 -0400)
edit.ml
lib/buf.ml
lib/rope.ml

diff --git a/edit.ml b/edit.ml
index c477612b17704fba6ed732f6b9260310fb72069a..49f71af6f76003846c56ff682453093e7c56a628 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,12 +1,12 @@
 open X11
 
-(*
-let font = font_load "Times New Roman:size=12"
-let font = font_load "Monaco:size=10::antialias=true:autohint=true"
-*)
-let font = font_load "Verdana:size=11:antialias=true:autohint=true"
-let tags_buf = ref Buf.create
-let edit_buf = ref Buf.create
+let font_times = font_load "Times New Roman:size=12"
+let font_monaco = font_load "Monaco:size=10::antialias=true:autohint=true"
+let font_verdana = font_load "Verdana:size=11:antialias=true:autohint=true"
+
+let font = font_verdana
+let tags_buf = ref Buf.empty
+let edit_buf = ref Buf.empty
 
 (* Drawing functions
  ******************************************************************************)
index 4a58ba7fe032575f274db968ef4b3fa0b47af4a0..a6be4564f341e107c744dd9f56e92c4072610c6b 100644 (file)
@@ -1,4 +1,7 @@
-type item = Ch | Word | Line
+type cursor = {
+  start : int;
+  stop : int
+}
 
 type buf = {
   path : string;
@@ -8,21 +11,30 @@ type buf = {
 let iter_from fn buf i =
   Rope.iter_from fn buf.rope i
 
-let create =
+let empty =
   { path = ""; rope = Rope.empty }
 
 let load path =
   { path = path; rope = Rope.from_string (Misc.load_file path) }
 
-let saveas buf path =
+let make_cursor buf start stop =
+  { start = (Rope.limit_index buf.rope start);
+    stop = (Rope.limit_index buf.rope stop) }
+
+let move_rune count csr buf ext =
+  let newstop = csr.stop + count in
+  let newstart = if ext then csr.start else newstop in
+  make_cursor buf newstart newstop
+
+let move_word count csr buf ext =
   ()
 
-let save buf =
-  saveas buf buf.path
+let move_line count csr buf ext =
+  ()
+
+(* Unit Tests *****************************************************************)
 
-let move item count buf pos =
-  match item with
-  | Ch   -> pos + count
-  | Word -> pos + count
-  | Line -> pos + count
+let run_unit_tests () =
+  let open Test in
+  ()
 
index 69dd58b52e28ec82e383ead75bbdcb9cd783f3aa..8acfbed27fb029fdd931b3953f422a4181eae86a 100644 (file)
@@ -19,6 +19,12 @@ let check_index rope i =
   if i < 0 || i >= (length rope) then
     raise (Out_of_bounds "Rope.check_index")
 
+let limit_index rope i =
+  if i < 0 then 0
+  else if i > 0 && i >= (length rope) then
+    ((length rope) - 1)
+  else i
+
 let join left right =
   let left_len = (length left) in
   let right_len = (length right) in