text editor issue is a problem with focus resolution
might require Focus.release, but may be incorrect use of Focus.request.
This commit is contained in:
File diff suppressed because one or more lines are too long
56
human.ml
56
human.ml
@ -1333,6 +1333,10 @@ module Nottui = struct
|
||||
module Ui = struct
|
||||
type may_handle = [ `Unhandled | `Handled ]
|
||||
|
||||
let may_handle (type a) (v : a option) (f : a -> may_handle) :
|
||||
may_handle =
|
||||
match v with Some v' -> f v' | None -> `Unhandled
|
||||
|
||||
let pp_may_handle ppf = function
|
||||
| `Unhandled -> F.pf ppf "`Unhandled"
|
||||
| `Handled -> F.pf ppf "`Handled"
|
||||
@ -2722,13 +2726,21 @@ module Nottui_widgets = struct
|
||||
|
||||
open Lwd.Infix
|
||||
|
||||
let eq_uc_c uc c = Uchar.(equal uc (of_char c))
|
||||
|
||||
type line = {
|
||||
focus : Focus.handle;
|
||||
state : (string * int) Lwd.var;
|
||||
ui : Ui.t Lwd.t;
|
||||
}
|
||||
|
||||
let eq_uc_c uc c = Uchar.(equal uc (of_char c))
|
||||
let line_make ?(focus = Focus.make ()) str =
|
||||
let state = Lwd.var (str, 0) in
|
||||
{ focus; state; ui = edit_field ~focus state }
|
||||
|
||||
let line_append ?(table = Lwd_table.make ()) ?focus str =
|
||||
let row = Lwd_table.append table in
|
||||
Lwd_table.set row (line_make ?focus str)
|
||||
|
||||
let copy_line_cursor (x : line) (y : line) =
|
||||
let _, xi = Lwd.peek x.state in
|
||||
@ -2736,43 +2748,33 @@ module Nottui_widgets = struct
|
||||
let yi = Int.max 0 (Int.min xi (String.length ys)) in
|
||||
Lwd.set y.state (ys, yi)
|
||||
|
||||
let row_of_cursor cursor f =
|
||||
Ui.may_handle (Lwd.peek cursor) (fun row -> f row)
|
||||
|
||||
let line_of_cursor cursor
|
||||
(f : line Lwd_table.row -> line -> Ui.may_handle) :
|
||||
Ui.may_handle =
|
||||
match Lwd.peek cursor with
|
||||
| Some row -> (
|
||||
match Lwd_table.get row with
|
||||
| Some line -> f row line
|
||||
| None -> `Unhandled)
|
||||
| None -> `Unhandled
|
||||
Ui.may_handle (Lwd.peek cursor) (fun row ->
|
||||
Ui.may_handle (Lwd_table.get row) (fun line -> f row line))
|
||||
|
||||
let cursor_move cursor
|
||||
(f : line Lwd_table.row -> line Lwd_table.row option) =
|
||||
match Lwd.peek cursor with
|
||||
| Some cursor_line -> (
|
||||
match f cursor_line with
|
||||
| Some cursor_row -> (
|
||||
match f cursor_row with
|
||||
| Some new_row ->
|
||||
(match Lwd_table.get new_row with
|
||||
| Some new_line ->
|
||||
(match Lwd_table.get new_line with
|
||||
| Some line' ->
|
||||
cursor_line |> Lwd_table.get
|
||||
|> Option.iter (fun line ->
|
||||
copy_line_cursor line line');
|
||||
Focus.request line'.focus
|
||||
cursor_row |> Lwd_table.get
|
||||
|> Option.iter (fun cursor_line ->
|
||||
copy_line_cursor cursor_line new_line);
|
||||
Focus.request new_line.focus
|
||||
| None -> ());
|
||||
Lwd.set cursor (Some new_line);
|
||||
Lwd.set cursor (Some new_row);
|
||||
`Handled
|
||||
| None -> `Unhandled)
|
||||
| None -> `Unhandled
|
||||
|
||||
let line_make ?(focus = Focus.make ()) str =
|
||||
let state = Lwd.var (str, 0) in
|
||||
{ focus; state; ui = edit_field ~focus state }
|
||||
|
||||
let line_append ?(table = Lwd_table.make ())
|
||||
?(focus = Focus.make ()) str =
|
||||
let row = Lwd_table.append table in
|
||||
Lwd_table.set row (line_make ~focus str)
|
||||
|
||||
let line_table_of_string ?(table = Lwd_table.make ())
|
||||
?(focus = Focus.make ()) (s : string) : Ui.t Lwd.t =
|
||||
(* Append lines from s to table *)
|
||||
@ -2832,12 +2834,12 @@ module Nottui_widgets = struct
|
||||
let str_prev, _ =
|
||||
Lwd.peek line_prev.state
|
||||
in
|
||||
Focus.request line_prev.focus;
|
||||
Lwd.set line_prev.state
|
||||
( str_prev ^ str,
|
||||
String.length str_prev );
|
||||
Focus.request line_prev.focus;
|
||||
Lwd_table.remove row;
|
||||
Lwd.set cursor (Some row_prev);
|
||||
Lwd_table.remove row;
|
||||
`Handled
|
||||
| None -> `Unhandled)
|
||||
| _ -> `Unhandled)
|
||||
|
||||
Reference in New Issue
Block a user