From 90f8c5e65c96f946ab079271b52112ec36d6c42c Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Fri, 17 May 2024 17:46:46 -0500 Subject: Resolve OOB error --- lib/grep.ml | 7 ++++--- lib/stitched_article.ml | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/grep.ml b/lib/grep.ml index 2e55b40..5690edc 100644 --- a/lib/grep.ml +++ b/lib/grep.ml @@ -295,8 +295,9 @@ type display_type = let pretty_print_parsed_content parsed_files = let padding = String.make headline_pattern_length ' ' in List.concat_map - (fun (file_name, line_number, line_content, _) -> + (fun (file_name, line_number, line_content, file_number) -> if line_number == 0 - then [ Bold ("--------- " ^ file_name); Normal line_content ] - else [ Normal (padding ^ line_content) ]) + then + [ file_number, Bold ("--------- " ^ file_name); file_number, Normal line_content ] + else [ file_number, Normal (padding ^ line_content) ]) parsed_files diff --git a/lib/stitched_article.ml b/lib/stitched_article.ml index ce7bc0c..f42812f 100644 --- a/lib/stitched_article.ml +++ b/lib/stitched_article.ml @@ -9,7 +9,7 @@ type state = ; scroll : int ; content : (string * int * string * int) array ; go_back : unit -> unit - ; content_pretty : Grep.display_type array + ; content_pretty : (int * Grep.display_type) array ; goto_todos_view : (unit -> unit) -> unit ; goto_done_view : (unit -> unit) -> unit } @@ -28,7 +28,7 @@ let rec render let img = let elements = Array.mapi - (fun i el -> Compontent.current_line size_x y scroll el (i + content_start)) + (fun i (_, el) -> Compontent.current_line size_x y scroll el (i + content_start)) (* TODO: Fix this ugly slow conversion *) (Array.to_seq content_pretty |> Seq.drop scroll |> Array.of_seq) in @@ -109,13 +109,14 @@ let rec render let[@warning "-8"] (editor :: args) = String.split_on_char ' ' (Sys.getenv "EDITOR") in - let selected_file, line_number, _, file_number_offset = - Array.get content (y - content_start) + let file_number_offset, _ = Array.get content_pretty (y - content_start) in + let selected_file, line_number, _, _ = + Array.get content (y - content_start - file_number_offset) in let full_path_file = Grep.execution_directory ^ "/" ^ selected_file in (* Because each file title consists of two lines, we need to account for the offset it adds by removing the file_number *) - let line_number_arg = "+" ^ Int.to_string (line_number - file_number_offset) in + let line_number_arg = "+" ^ Int.to_string line_number in let full_args = Array.append (Array.of_list args) [| ""; full_path_file; line_number_arg |] in -- cgit v1.2.3