]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
fixed Rope.nextln/prevln which was breaking scrolling
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 13 Nov 2017 15:49:08 +0000 (10:49 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 13 Nov 2017 15:49:08 +0000 (10:49 -0500)
edit.ml
lib/rope.ml
tests/rope_tests.ml

diff --git a/edit.ml b/edit.ml
index 0cdbbe11ad9dc673500f22f8eef4a3d72cb85de0..6c41a32f649fd4032eb7b5a89c5245495edcc71d 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -34,18 +34,18 @@ let onshutdown () = ()
 
 let onevent evnt =
   try match evnt with
-  | Focus state      -> onfocus state
-  | KeyPress e       -> onkeypress e.mods e.rune
-  | MouseClick e     -> onmousebtn e.mods e.btn e.x e.y true
-  | MouseRelease e   -> onmousebtn e.mods e.btn e.x e.y false
-  | MouseMove e      -> onmousemove e.mods e.x e.y
-  | Paste e          -> () (*print_endline "paste"*)
-  | Command e        -> () (*print_endline "command"*)
-  | PipeClosed e     -> () (*print_endline "pipeclosed"*)
-  | PipeWriteReady e -> () (*print_endline "pipewriteready"*)
-  | PipeReadReady e  -> () (*print_endline "pipereadready"*)
-  | Update e         -> onupdate e.width e.height
-  | Shutdown         -> onshutdown ()
+    | Focus state      -> onfocus state
+    | KeyPress e       -> onkeypress e.mods e.rune
+    | MouseClick e     -> onmousebtn e.mods e.btn e.x e.y true
+    | MouseRelease e   -> onmousebtn e.mods e.btn e.x e.y false
+    | MouseMove e      -> onmousemove e.mods e.x e.y
+    | Paste e          -> () (*print_endline "paste"*)
+    | Command e        -> () (*print_endline "command"*)
+    | PipeClosed e     -> () (*print_endline "pipeclosed"*)
+    | PipeWriteReady e -> () (*print_endline "pipewriteready"*)
+    | PipeReadReady e  -> () (*print_endline "pipereadready"*)
+    | Update e         -> onupdate e.width e.height
+    | Shutdown         -> onshutdown ()
   with e -> begin
     print_endline (Printexc.to_string e);
     Printexc.print_backtrace stdout
index f3c16fb13487d762865017fdff0820ff6a9291ab..873c114ab1d69c33a6a9040a8f5faf35f6430224 100644 (file)
@@ -53,7 +53,8 @@ let rec getb rope i =
 let rec getc rope i =
   check_index rope i;
   match rope with
-  | Leaf (s,off,_) ->
+  | Leaf (s,off,_) -> (Char.code s.[off + i])
+(*
       let c = (Char.code s.[off + i]) in
       let len = (length rope) in
       let next = (i + 1) in
@@ -61,6 +62,7 @@ let rec getc rope i =
         0x0A
       else
         c
+*)
   | Node (l,r,h,len) ->
       let left_len = (length l) in
       if i < left_len then
@@ -218,7 +220,7 @@ let is_eol rope pos =
 
 let rec move_till step testfn rope pos =
   let adjust_pos = if step < 0 then prevc else nextc in
-  if (testfn rope pos) || pos == 0 || pos == (last rope) then pos
+  if (testfn rope pos) then pos
   else (move_till step testfn rope (adjust_pos rope pos))
 
 let to_bol rope pos =
index b98eefbb4c73cfc1585ecc4cb8d23d98521c969c..64115bd0fc3eb116290d91f3c3fb9aa4c110df6a 100644 (file)
@@ -82,10 +82,11 @@ let  () =
     let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 0, 2) in
     assert( (getc rope (1)) == Char.code 'b' );
   );
-  test "getc : return \\n for \\r\\n" (fun () ->
+(*  test "getc : return \\n for \\r\\n" (fun () ->
     let rope = from_string "\r\n" in
     assert( (getc rope (0)) == Char.code '\n' );
   );
+*)
   test "getc : return \\r for \\r at end of string" (fun () ->
     let rope = from_string "\r" in
     assert( (getc rope (0)) == Char.code '\r' );
@@ -167,14 +168,14 @@ let  () =
     let rope = Leaf("abc", 0, 3) in
     assert( is_eol rope 2 );
   );
-  test "is_eol : should return true if pos is last char of line with \n ending" (fun () ->
+  test "is_eol : should return true if pos is last char of line with \\n ending" (fun () ->
     let rope = Leaf("abc\n", 0, 4) in
     assert( is_eol rope 3 );
   );
-  test "is_eol : should return true if pos is last char of line with \r\n ending" (fun () ->
+(*  test "is_eol : should return true if pos is last char of line with \\r\\n ending" (fun () ->
     let rope = Leaf("abc\r\n", 0, 5) in
     assert( is_eol rope 3 );
-  );
+  );*)
   test "is_eol : should return false if pos is not last char of line" (fun () ->
     let rope = Leaf("abcd\n", 0, 5) in
     assert( (is_eol rope 2) == false );