From: Michael D. Lowis Date: Thu, 25 Jan 2018 02:48:07 +0000 (-0500) Subject: fixed click to character mapping code X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f214000dba8fddfcf5fbe321aa1df27ccd8eb6b0;p=archive%2Ftide-ocaml.git fixed click to character mapping code --- diff --git a/lib/draw.ml b/lib/draw.ml index 7bb2dbf..5d80ed2 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -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; diff --git a/lib/draw.mli b/lib/draw.mli index e0645ab..ff613ca 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -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) diff --git a/lib/view.ml b/lib/view.ml index b47a9ce..4a53186 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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 }