Skip to content

Commit

Permalink
Added refiltering on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed May 4, 2023
1 parent b4d9177 commit cab5eb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/docfd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
44 changes: 23 additions & 21 deletions src/multi_file_view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 :=
Expand Down Expand Up @@ -373,7 +375,7 @@ let keyboard_handler
`Handled
)
| (`ASCII 'r', []) -> (
reload_document_selected ();
reload_document_selected ~skip_filter:false ();
`Handled
)
| (`Tab, []) -> (
Expand Down

0 comments on commit cab5eb0

Please sign in to comment.