From cab5eb0b3a8a8b56003be99113876086994204d6 Mon Sep 17 00:00:00 2001 From: Darren L Date: Thu, 4 May 2023 11:22:52 +1000 Subject: [PATCH] Added refiltering on reload --- src/docfd.ml | 2 +- src/multi_file_view.ml | 44 ++++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/docfd.ml b/src/docfd.ml index 8e07ba7..a8b8bdc 100644 --- a/src/docfd.ml +++ b/src/docfd.ml @@ -198,7 +198,7 @@ let run if Float.abs (new_stats.st_mtime -. old_stats.st_mtime) >= 0.000_001 then ( (match Lwd.peek Ui_base.Vars.ui_mode with | Ui_single_file -> Single_file_view.reload_document doc - | Ui_multi_file -> Multi_file_view.reload_document_selected () + | Ui_multi_file -> Multi_file_view.reload_document_selected ~skip_filter:true () ); ); loop () diff --git a/src/multi_file_view.ml b/src/multi_file_view.ml index b0cb9d3..99ca335 100644 --- a/src/multi_file_view.ml +++ b/src/multi_file_view.ml @@ -28,26 +28,6 @@ let set_search_result_selected ~choice_count n = let n = Misc_utils.bound_selection ~choice_count n in Lwd.set Vars.index_of_search_result_selected n -let reload_document_selected () : unit = - let arr = Lwd.peek Vars.documents in - if Array.length arr > 0 then ( - let index = Lwd.peek Vars.index_of_document_selected in - let doc = arr.(index) in - match doc.path with - | None -> () - | Some path -> ( - match Document.of_path path with - | Ok x -> ( - let m = Lwd.peek Ui_base.Vars.all_documents - |> String_option_map.add (Some path) x - in - Lwd.set Ui_base.Vars.all_documents m; - arr.(index) <- x; - ) - | Error _ -> () - ) - ) - let filter_documents ~all_documents = let search_constraints = !Vars.search_constraints in let arr = @@ -80,6 +60,28 @@ let filter_documents ~all_documents = ); Lwd.set Vars.documents arr +let reload_document_selected ~skip_filter () : unit = + let arr = Lwd.peek Vars.documents in + if Array.length arr > 0 then ( + let index = Lwd.peek Vars.index_of_document_selected in + let doc = arr.(index) in + match doc.path with + | None -> () + | Some path -> ( + match Document.of_path path with + | Ok x -> ( + let m = Lwd.peek Ui_base.Vars.all_documents + |> String_option_map.add (Some path) x + in + Lwd.set Ui_base.Vars.all_documents m; + if not skip_filter then ( + filter_documents ~all_documents:m + ); + ) + | Error _ -> () + ) + ) + let update_search_constraints () = reset_document_selected (); Vars.search_constraints := @@ -373,7 +375,7 @@ let keyboard_handler `Handled ) | (`ASCII 'r', []) -> ( - reload_document_selected (); + reload_document_selected ~skip_filter:false (); `Handled ) | (`Tab, []) -> (