let draw view csr =
let view = (resize view (Draw.Cursor.max_width csr)) in
- (*Draw.dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;*)
Draw.buffer csr view.buf (Scrollmap.first view.map);
view
******************************************************************************)
let onfocus focused = ()
-let onkeypress mods rune = ()
+let onkeypress mods rune =
+ edit_view := View.scroll_dn !edit_view
let onmousebtn mods btn x y pressed =
match btn with
| 1 -> ()
| 2 -> ()
| 3 -> ()
- | 4 -> (if pressed then edit_view := View.scroll_up !edit_view)
- | 5 -> (if pressed then edit_view := View.scroll_dn !edit_view)
+ | 4 -> (edit_view := View.scroll_up !edit_view)
+ | 5 -> (edit_view := View.scroll_dn !edit_view)
| _ -> ()
let onmousemove mods x y = ()
type t = {
- start : int;
path : string;
rope : Rope.t
}
let empty =
- { start = 0; path = ""; rope = Rope.empty }
+ { path = ""; rope = Rope.empty }
let load path =
- { start = 0; path = path; rope = Rope.from_string (Misc.load_file path) }
+ { path = path; rope = Rope.from_string (Misc.load_file path) }
let rope buf =
buf.rope
-let start buf =
- buf.start
-
let iter_from fn buf i =
Rope.iter_from fn buf.rope i
let run_unit_tests () =
let open Test in
()
-
+(*
+module Cursor : sig
+ type t
+ val to_offset : t -> int
+ val next_rune : t -> t
+ val prev_rune : t -> t
+ val next_line : t -> t
+ val prev_line : t -> t
+end
+*)
+
type t
val empty : t
val load : string -> t
val rope : t -> Rope.t
-val start : t -> int
val iter_from : (int -> bool) -> t -> int -> unit
val iteri_from : (int -> int -> bool) -> t -> int -> unit
csr.x <- csr.x + 14;
vrule csr.height csr
-let edit csr buf off =
+let edit csr buf =
dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
- buffer csr buf off
+ buffer csr buf
let is_eol rope pos =
if pos >= (last rope) then true
- else let c = (getc rope (pos+1)) in
- (c == 0x0A || c == 0x0D)
+ else ((getc rope (pos+1)) == 0x0A)
let is_bow rope pos = false
);
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 2 );
+ 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
let rope = Leaf("\nabc\n", 0, 5) in
assert( (to_bol rope 2) == 1 );
);
-
()
(*
lines : int array
}
+let rec find_line lines off idx =
+ if idx > 0 && lines.(idx) > off then
+ find_line lines off (idx - 1)
+ else
+ idx
+
let make buf width off =
let csr = Draw.Cursor.make (width, 0) 0 0 in
let bol = (Rope.to_bol (Buf.rope buf) off) in
let lines = ref [bol] in
+ let csr = Draw.Cursor.make (width, 0) 0 0 in
let process_glyph i c =
if (Draw.Cursor.next_glyph csr c) then
lines := i :: !lines;
- ((Rope.is_eol (Buf.rope buf) i) == false)
+ ((Rope.is_eol (Buf.rope buf) i) == false)
in
Buf.iteri_from process_glyph buf off;
- { width = width; index = 0; lines = (Array.of_list (List.rev !lines)) }
+ let lines = (Array.of_list (List.rev !lines)) in
+ let index = (find_line lines off ((Array.length lines) - 1)) in
+ { width = width; lines = lines; index = index }
let first map =
+ (*
+ Printf.printf "%d: %d" map.index map.lines.(map.index);
+ print_endline "";
+ *)
map.lines.(map.index)
let bopl buf off =
- let next = ((Rope.to_bol (Buf.rope buf) off) - 1) in
+ let next = ((Rope.to_bol (Buf.rope buf) off) - 2) in
Rope.limit_index (Buf.rope buf) next
let bonl buf off =
- let next = ((Rope.to_eol (Buf.rope buf) off) + 1) in
+ let next = ((Rope.to_eol (Buf.rope buf) off) + 2) in
Rope.limit_index (Buf.rope buf) next
let scroll_up map buf =
if (next >= 0) then
{ map with index = next }
else
- let map = make buf map.width (bopl buf map.lines.(0)) in
- { map with index = (Array.length map.lines) - 1 }
+ make buf map.width (bopl buf map.lines.(0))
let scroll_dn map buf =
let next = map.index + 1 in
uint64_t t = getmillis();
while (XPending(X.display)) {
XNextEvent(X.display, &e);
- //printf("%d ", e.type);
+ printf("%d ", e.type);
if (!XFilterEvent(&e, None) && EventHandlers[e.type]) {
event = EventHandlers[e.type](&e);
if (event != Val_int(TNone))
caml_callback(cbfn, event);
}
}
- //puts("");
- //printf("time 1 %lu ", getmillis()-t);
+ puts("");
+ printf("time 1 %lu ", getmillis()-t);
t = getmillis();
if (X.running) {
caml_callback(cbfn, mkvariant(TUpdate, 2, Val_int(X.width), Val_int(X.height)));
}
XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
}
- //printf("\ntime 2 %lu\n", getmillis()-t);
+ printf("\ntime 2 %lu\n", getmillis()-t);
XFlush(X.display);
}
CAMLreturn(Val_unit);