tree_nav cursor movement
This commit is contained in:
File diff suppressed because one or more lines are too long
29
human.ml
29
human.ml
@ -2910,18 +2910,19 @@ module Nottui_widgets = struct
|
||||
let tree_nav ?(focus = Focus.make ()) tree path : Ui.t Lwd.t Lwt.t =
|
||||
let table = Lwd_table.make () in
|
||||
|
||||
(*
|
||||
Option.iter
|
||||
(fun cursor ->
|
||||
Option.iter (fun first -> Focus.request first.focus)
|
||||
@@ Lwd_table.get cursor)
|
||||
(Lwd.peek cursor); *)
|
||||
let cursor_move cursor
|
||||
(f : 'a Lwd_table.row -> 'a Lwd_table.row option) =
|
||||
match Lwd.peek cursor with
|
||||
| Some cursor_row -> (
|
||||
match f cursor_row with
|
||||
| Some new_row ->
|
||||
(match Lwd_table.get new_row with
|
||||
| Some (new_line_focus, _) ->
|
||||
cursor_row |> Lwd_table.get
|
||||
|> Option.iter (fun (cursor_line_focus, _) ->
|
||||
Focus.release cursor_line_focus);
|
||||
Focus.request new_line_focus
|
||||
| None -> ());
|
||||
Lwd.set cursor (Some new_row);
|
||||
`Handled
|
||||
| None -> `Unhandled)
|
||||
@ -2931,11 +2932,23 @@ module Nottui_widgets = struct
|
||||
(* Build view of tree *)
|
||||
let open Lwt.Infix in
|
||||
Nav.S.Tree.list tree path >>= fun treelist ->
|
||||
List.iter (fun te -> Lwd_table.append' table te) treelist;
|
||||
List.iter
|
||||
(fun te -> Lwd_table.append' table (Focus.make (), te))
|
||||
treelist;
|
||||
let cursor = Lwd.var @@ Lwd_table.first table in
|
||||
Option.iter
|
||||
(fun cursor ->
|
||||
Option.iter (fun (f, _) -> Focus.request f)
|
||||
@@ Lwd_table.get cursor)
|
||||
(Lwd.peek cursor);
|
||||
Lwt.return
|
||||
(Lwd_table.map_reduce
|
||||
(fun _ (s, _) -> Lwd.pure (string s))
|
||||
(fun _ (f, (s, _)) ->
|
||||
Lwd.map
|
||||
~f:(fun focus_h ->
|
||||
if Focus.has_focus focus_h then string ~attr:A.cursor s
|
||||
else string s)
|
||||
(Focus.status f))
|
||||
(Lwd_utils.lift_monoid Ui.pack_y)
|
||||
table
|
||||
|> Lwd.join
|
||||
|
||||
Reference in New Issue
Block a user