added Focus.releases for line_table
This commit is contained in:
File diff suppressed because one or more lines are too long
42
human.ml
42
human.ml
@ -1220,6 +1220,8 @@ module Nottui = struct
|
|||||||
val status : handle -> status Lwd.t
|
val status : handle -> status Lwd.t
|
||||||
val has_focus : status -> bool
|
val has_focus : status -> bool
|
||||||
val merge : status -> status -> status
|
val merge : status -> status -> status
|
||||||
|
val pp_var : Format.formatter -> var -> unit
|
||||||
|
val pp_status : Format.formatter -> status -> unit
|
||||||
end = struct
|
end = struct
|
||||||
type var = int Lwd.var
|
type var = int Lwd.var
|
||||||
type status = Empty | Handle of int * var | Conflict of int
|
type status = Empty | Handle of int * var | Conflict of int
|
||||||
@ -1240,6 +1242,8 @@ module Nottui = struct
|
|||||||
|
|
||||||
let request_var (v : var) =
|
let request_var (v : var) =
|
||||||
incr clock;
|
incr clock;
|
||||||
|
Log.debug (fun m ->
|
||||||
|
m "Focus.request_var v=%d clock=%d" (Lwd.peek v) !clock);
|
||||||
Lwd.set v !clock
|
Lwd.set v !clock
|
||||||
|
|
||||||
let request ((v, _) : handle) = request_var v
|
let request ((v, _) : handle) = request_var v
|
||||||
@ -1250,15 +1254,20 @@ module Nottui = struct
|
|||||||
|
|
||||||
let merge s1 s2 : status =
|
let merge s1 s2 : status =
|
||||||
match (s1, s2) with
|
match (s1, s2) with
|
||||||
| Empty, x | x, Empty -> x
|
| (Empty | Handle (0, _)), x | x, (Empty | Handle (0, _)) -> x
|
||||||
| _, Handle (0, _) -> s1
|
|
||||||
| Handle (0, _), _ -> s2
|
|
||||||
| Handle (i1, _), Handle (i2, _) when i1 = i2 -> s1
|
| Handle (i1, _), Handle (i2, _) when i1 = i2 -> s1
|
||||||
| (Handle (i1, _) | Conflict i1), Conflict i2 when i1 < i2 -> s2
|
| (Handle (i1, _) | Conflict i1), Conflict i2 when i1 < i2 -> s2
|
||||||
| (Handle (i1, _) | Conflict i1), Handle (i2, _) when i1 < i2 ->
|
| (Handle (i1, _) | Conflict i1), Handle (i2, _) when i1 < i2 ->
|
||||||
Conflict i2
|
Conflict i2
|
||||||
| Conflict _, (Handle (_, _) | Conflict _) -> s1
|
| Conflict _, (Handle (_, _) | Conflict _) -> s1
|
||||||
| Handle (i1, _), (Handle (_, _) | Conflict _) -> Conflict i1
|
| Handle (i1, _), (Handle (_, _) | Conflict _) -> Conflict i1
|
||||||
|
|
||||||
|
let pp_var ppf v = F.pf ppf "%d" (Lwd.peek v)
|
||||||
|
|
||||||
|
let pp_status ppf = function
|
||||||
|
| Empty -> F.pf ppf "Empty"
|
||||||
|
| Handle (i, v) -> F.pf ppf "Handle (%d, %a)" i pp_var v
|
||||||
|
| Conflict i -> F.pf ppf "Conflict %d" i
|
||||||
end
|
end
|
||||||
|
|
||||||
module Gravity : sig
|
module Gravity : sig
|
||||||
@ -1594,7 +1603,9 @@ module Nottui = struct
|
|||||||
let zcat xs = Lwd_utils.reduce pack_z xs
|
let zcat xs = Lwd_utils.reduce pack_z xs
|
||||||
let has_focus t = Focus.has_focus t.focus
|
let has_focus t = Focus.has_focus t.focus
|
||||||
|
|
||||||
let rec pp ppf t = Format.fprintf ppf "@[<hov>%a@]" pp_desc t.desc
|
let rec pp ppf t =
|
||||||
|
F.pf ppf "@[<hov>focus=%a %a@]" Focus.pp_status t.focus pp_desc
|
||||||
|
t.desc
|
||||||
|
|
||||||
and pp_desc ppf = function
|
and pp_desc ppf = function
|
||||||
| Atom a ->
|
| Atom a ->
|
||||||
@ -2098,7 +2109,7 @@ module Nottui = struct
|
|||||||
|
|
||||||
let image vg { size; view; _ } =
|
let image vg { size; view; _ } =
|
||||||
let w, h = V2.to_tuple size in
|
let w, h = V2.to_tuple size in
|
||||||
(*Log.debug (fun m -> m "Renderer.image view=%a" Ui.pp view);*)
|
Log.debug (fun m -> m "Renderer.image view=%a " Ui.pp view);
|
||||||
(render_node vg 0. 0. w h w h view).image
|
(render_node vg 0. 0. w h w h view).image
|
||||||
|
|
||||||
let dispatch_raw_key st key =
|
let dispatch_raw_key st key =
|
||||||
@ -2223,6 +2234,8 @@ module Nottui = struct
|
|||||||
let dir = if List.mem `Shift mods then `Prev else `Next in
|
let dir = if List.mem `Shift mods then `Prev else `Next in
|
||||||
dispatch_key st (`Focus dir, mods)
|
dispatch_key st (`Focus dir, mods)
|
||||||
| `Unhandled, (`Focus dir, _) ->
|
| `Unhandled, (`Focus dir, _) ->
|
||||||
|
Log.warn (fun m ->
|
||||||
|
m "Renderer.dispatch_focus %a" pp_key key);
|
||||||
if dispatch_focus st.view dir then `Handled else `Unhandled
|
if dispatch_focus st.view dir then `Handled else `Unhandled
|
||||||
| `Unhandled, _ -> `Unhandled
|
| `Unhandled, _ -> `Unhandled
|
||||||
|
|
||||||
@ -2767,7 +2780,8 @@ module Nottui_widgets = struct
|
|||||||
| Some new_line ->
|
| Some new_line ->
|
||||||
cursor_row |> Lwd_table.get
|
cursor_row |> Lwd_table.get
|
||||||
|> Option.iter (fun cursor_line ->
|
|> Option.iter (fun cursor_line ->
|
||||||
copy_line_cursor cursor_line new_line);
|
copy_line_cursor cursor_line new_line;
|
||||||
|
Focus.release cursor_line.focus);
|
||||||
Focus.request new_line.focus
|
Focus.request new_line.focus
|
||||||
| None -> ());
|
| None -> ());
|
||||||
Lwd.set cursor (Some new_row);
|
Lwd.set cursor (Some new_row);
|
||||||
@ -2820,6 +2834,7 @@ module Nottui_widgets = struct
|
|||||||
in
|
in
|
||||||
Lwd.set old_line.state (o_str, pos);
|
Lwd.set old_line.state (o_str, pos);
|
||||||
let new_line = line_make n_str in
|
let new_line = line_make n_str in
|
||||||
|
Focus.release old_line.focus;
|
||||||
Focus.request new_line.focus;
|
Focus.request new_line.focus;
|
||||||
Lwd.set cursor
|
Lwd.set cursor
|
||||||
(Some (Lwd_table.after old_row ~set:new_line));
|
(Some (Lwd_table.after old_row ~set:new_line));
|
||||||
@ -2827,22 +2842,23 @@ module Nottui_widgets = struct
|
|||||||
| `Backspace, [] ->
|
| `Backspace, [] ->
|
||||||
line_of_cursor cursor (fun row line ->
|
line_of_cursor cursor (fun row line ->
|
||||||
let str, pos = Lwd.peek line.state in
|
let str, pos = Lwd.peek line.state in
|
||||||
match Lwd_table.prev row with
|
Ui.may_handle (Lwd_table.prev row)
|
||||||
| Some row_prev when pos = 0 -> (
|
(fun row_prev ->
|
||||||
match Lwd_table.get row_prev with
|
if pos = 0 then
|
||||||
| Some line_prev ->
|
Ui.may_handle (Lwd_table.get row_prev)
|
||||||
|
(fun line_prev ->
|
||||||
let str_prev, _ =
|
let str_prev, _ =
|
||||||
Lwd.peek line_prev.state
|
Lwd.peek line_prev.state
|
||||||
in
|
in
|
||||||
|
Focus.release line.focus;
|
||||||
Focus.request line_prev.focus;
|
Focus.request line_prev.focus;
|
||||||
Lwd.set line_prev.state
|
Lwd.set line_prev.state
|
||||||
( str_prev ^ str,
|
( str_prev ^ str,
|
||||||
String.length str_prev );
|
String.length str_prev );
|
||||||
Lwd.set cursor (Some row_prev);
|
Lwd.set cursor (Some row_prev);
|
||||||
Lwd_table.remove row;
|
Lwd_table.remove row;
|
||||||
`Handled
|
`Handled)
|
||||||
| None -> `Unhandled)
|
else `Unhandled))
|
||||||
| _ -> `Unhandled)
|
|
||||||
| _ -> `Unhandled))
|
| _ -> `Unhandled))
|
||||||
(Focus.status focus)
|
(Focus.status focus)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user