]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
fixed click to character mapping code
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 25 Jan 2018 02:48:07 +0000 (21:48 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 25 Jan 2018 02:48:07 +0000 (21:48 -0500)
lib/draw.ml
lib/draw.mli
lib/view.ml

index 7bb2dbfacea82592c1e1d6585b18c720f4193001..5d80ed2f9bf2e4ab9020224a85d55a1c483714f8 100644 (file)
@@ -120,9 +120,17 @@ let vrule height csr =
   rule_bkg 1 (height - csr.y) csr;
   csr.x <- csr.x + 1
 
+let make_line_array lines nlines =
+  let lines = (Array.of_list (List.rev !lines)) in
+  let line_ary = (Array.make nlines (-1)) in
+  Array.blit lines 0 line_ary 0;
+  lines
+
 let buffer csr buf clr off =
-  dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
+  let height = (csr.height - csr.y) in
+  dark_bkg (csr.width - csr.x) height csr;
   csr.y <- csr.y + 2;
+  let nlines = ((height -2) / font_height) in
   let num = ref 0 and csr = (restart csr 2 0)
   and boxes = ref [] and lines = ref [] in
   let draw_rune c =
@@ -137,7 +145,7 @@ let buffer csr buf clr off =
   in
   Buf.iter draw_rune buf off;
   List.iter X11.draw_rect !boxes; (* draw selection boxes *)
-  (!num, !lines)
+  (!num, (make_line_array lines nlines))
 
 let status csr str =
   dark_bkg csr.width (4 + font_height) csr;
index e0645abe99325f1c5d5f471eb02673a4aaa28d4f..ff613ca36abb99a59ef16fdad2c83098b47cfe36 100644 (file)
@@ -29,7 +29,7 @@ val dark_bkg : int -> int -> Cursor.t -> unit
 val light_bkg : int -> int -> Cursor.t -> unit
 val rule_bkg : int -> int -> Cursor.t -> unit
 
-val buffer : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int list)
+val buffer : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int array)
 
 val string : string -> Cursor.t -> unit
 val hrule : int -> Cursor.t -> unit
@@ -38,4 +38,4 @@ val vrule : int -> Cursor.t -> unit
 val status : Cursor.t -> string -> unit
 val tags : Cursor.t -> Buf.t -> unit
 val scroll : Cursor.t -> (float * float) -> unit
-val edit : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int list)
+val edit : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int array)
index b47a9ce22a1a224054a47e5db8070effb26c0ce6..4a53186707e511e28db8620c46a0cf4841dd2e51 100644 (file)
@@ -1,6 +1,6 @@
 type t = {
   num : int;
-  lines: int list;
+  lines: int array;
   buf : Buf.t;
   map : Scrollmap.t;
   clr : Colormap.t;
@@ -9,7 +9,7 @@ type t = {
 }
 
 let from_buffer buf width height =
-  { num = 0; buf = buf; lines = [];
+  { num = 0; buf = buf; lines = [||];
     map = Scrollmap.make buf width 0;
     clr = Colormap.make (Buf.make_lexer buf);
     pos = (0,0);
@@ -40,12 +40,11 @@ let get_col_offset buf off w x =
 let get_at view x y =
   let sx,sy = view.pos and w,h = view.dim in
   let off =
-    try List.nth view.lines ((h - (y + 2)) / Draw.font.height)
-    with Failure _ -> Buf.length view.buf
+    try view.lines.((y - sy - 2) / Draw.font.height)
+    with Invalid_argument _ -> ((Buf.length view.buf) - 1)
   in
   get_col_offset view.buf off (w - sx) (x - sx)
 
-
 let select view start stop =
   { view with buf = Buf.select view.buf start stop }