From 9f3d3d40ddf6db70f8395adf4290241f7c5735db Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Wed, 15 May 2024 12:32:39 -0500 Subject: Update state management --- lib/stitched_article.ml | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'lib/stitched_article.ml') diff --git a/lib/stitched_article.ml b/lib/stitched_article.ml index c71ca14..66a108e 100644 --- a/lib/stitched_article.ml +++ b/lib/stitched_article.ml @@ -10,11 +10,14 @@ type state = ; content : (string * int * string * int) array ; go_back : unit -> unit ; content_pretty : Grep.display_type array - ; todo_state : Todos.state option + ; goto_todos_view : (unit -> unit) -> unit } (* TODO: Use grep -l to filter notes by regexp and rerender those files*) -let rec render t ({ pos; scroll; content_pretty; go_back; content; todo_state } as state) = +let rec render + t + ({ pos; scroll; content_pretty; go_back; content; goto_todos_view } as state) + = let size_x, size_y = Common.Term.size t in let x, y = pos in let img = @@ -50,26 +53,7 @@ let rec render t ({ pos; scroll; content_pretty; go_back; content; todo_state } | `Key (`ASCII 'j', []) | `Key (`ASCII 'N', [ `Ctrl ]) -> scroll_down () | `Key (`ASCII 'k', []) | `Key (`ASCII 'P', [ `Ctrl ]) -> scroll_up () | `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) } - | `Key (`ASCII '2', []) -> - (match todo_state with - | Some todo_state -> - Todos.render - t - { todo_state with - goto_headlines = - (fun new_state -> render t { state with todo_state = Some new_state }) - } - | None -> - let todo_content = Grep.get_todos () |> Grep.parse_todo_string in - let todo_pretty = Grep.pretty_format_todo todo_content in - let todo_state = - Todos.init - ~goto_headlines:(fun new_state -> - render t { state with todo_state = Some new_state }) - ~content:(todo_content |> Array.of_list) - ~content_pretty:(todo_pretty |> Array.of_list) - in - Todos.render t todo_state) + | `Key (`ASCII '2', []) -> goto_todos_view (fun () -> render t state) | `Key (`ASCII 'e', []) | `Key (`Enter, []) -> (* Editor might be set with extra args, in that case we need to separate these *) let[@warning "-8"] (editor :: args) = -- cgit v1.2.3