From: Michael D. Lowis Date: Mon, 13 Nov 2017 15:49:08 +0000 (-0500) Subject: fixed Rope.nextln/prevln which was breaking scrolling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=525fc218ed2dabe6edc96395ac8e2db32662a3ba;p=archive%2Ftide-ocaml.git fixed Rope.nextln/prevln which was breaking scrolling --- diff --git a/edit.ml b/edit.ml index 0cdbbe1..6c41a32 100644 --- 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 diff --git a/lib/rope.ml b/lib/rope.ml index f3c16fb..873c114 100644 --- a/lib/rope.ml +++ b/lib/rope.ml @@ -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 = diff --git a/tests/rope_tests.ml b/tests/rope_tests.ml index b98eefb..64115bd 100644 --- a/tests/rope_tests.ml +++ b/tests/rope_tests.ml @@ -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 );