Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/api-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3813,6 +3813,24 @@ boolean property. Removing it restores editable behavior. Applications that
used `disabled` solely to prevent edits may switch to `read_only` when users
should retain selection and copying.

The experimental self-drawn native backend now enforces the same contract:
`Lui_text_input.accepts_edits` gates insert, delete, paste, cut-deletion, undo
and IME commit/composition, while focus, selection, copy and caret navigation
remain available. Typed virtual-list `overscan` and `item-extent` are read by
`Lui_layout` with precedence over legacy `data-overscan` / `data-item-extent`.

### Native bridge registrar is a polymorphic record

`Lui_native_bridge.register` takes `~register_named` as
`{ register_named : 'a. string -> 'a -> unit }` instead of a bare function.
Wrap `Callback.register` (or a test stub) in that record:

```ocaml
Lui_native_bridge.register
~register_named:{ register_named = Callback.register }
"lui_ocaml" bridge
```

### Tabs, lifecycle and scroll results

Ordinary `tabs` keep their application-owned content. Arrow keys activate the
Expand Down
4 changes: 2 additions & 2 deletions examples/components/native/components_bridge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ let () =
Printexc.record_backtrace true;
Callback.register "lui_ocaml_init" initialize;
Callback.register "lui_kotlin_init" initialize;
Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge;
Lui_native_bridge.register ~register_named:Callback.register "lui_kotlin" bridge
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge;
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_kotlin" bridge
2 changes: 1 addition & 1 deletion examples/markdown/native/markdown_bridge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ let initialize platform_code host_code =

let () =
Callback.register "lui_ocaml_init" initialize;
Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge
2 changes: 1 addition & 1 deletion examples/navigation/native/navigation_bridge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ let initialize _platform host_code =
let () =
Printexc.record_backtrace true;
Callback.register "lui_ocaml_init" initialize;
Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge
2 changes: 1 addition & 1 deletion examples/split/native/split_bridge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ let initialize platform_code host_code =

let () =
Callback.register "lui_ocaml_init" initialize;
Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge
2 changes: 1 addition & 1 deletion examples/todos/native/todos_bridge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ let initialize platform_code host_code =

let () =
Callback.register "lui_ocaml_init" initialize;
Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge
Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge
34 changes: 25 additions & 9 deletions platform/native/lui_input/lui_text_input.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ let composing st = Lui_ime.composing st.ime
let sel_lo st = min st.anchor st.caret
let sel_hi st = max st.anchor st.caret

(* Whether the node's focused field accepts edits — admits
TextChanged. *)
(* Whether the node is a text field that admits TextChanged — focus,
selection and copy still apply when [read-only] is set. *)
let editable store node =
node <> 0 && Lui_query.event_supported store node (TextChanged (node, ""))

(* User edits (insert, delete, paste, IME commit, undo) require an
editable field that is not marked read-only. *)
let accepts_edits store node =
editable store node && not (Lui_store.bool_prop store node "read-only")

(* Session ids — every attach starts a new session so model
responses to one session cannot leak into the next. *)
let session_seq = ref 0
Expand Down Expand Up @@ -242,11 +247,13 @@ let edit_key hooks store rects st ~(k : Lui_input.key)
then Lui_query.submit store n else []
| _ -> Lui_query.submit store n) )
| Lui_input.Backspace ->
if sel_hi st > sel_lo st then splice st ""
if not (accepts_edits store n) then (st, [])
else if sel_hi st > sel_lo st then splice st ""
else if caret > 0 then delete_between st (prev caret) caret
else (st, [])
| Lui_input.Delete ->
if sel_hi st > sel_lo st then splice st ""
if not (accepts_edits store n) then (st, [])
else if sel_hi st > sel_lo st then splice st ""
else if caret < String.length cur then
delete_between st caret (next caret)
else (st, [])
Expand Down Expand Up @@ -309,7 +316,7 @@ let apply_ime store st actions =
nothing or finds no editable target *)
(match !st.node with
| 0 -> [ `Repaint ]
| n when Lui_query.node_enabled store n && editable store n ->
| n when Lui_query.node_enabled store n && accepts_edits store n ->
let st', acts = splice !st s in
st := st';
`Repaint :: acts
Expand All @@ -321,11 +328,20 @@ let apply_ime store st actions =
(!st, out)

(* Feed one IME event into the embedded state machine and apply what
it asks for. *)
it asks for. Read-only fields keep caret tracking but reject
composition and commit so the shadow never changes. *)
let feed_ime store st ev =
let ime, actions = Lui_ime.feed_event st.ime ev in
let st, acts = apply_ime store { st with ime } actions in
(st, acts)
let reject_edit =
match ev with
| `Editing _ | `Commit _ ->
st.node <> 0 && not (accepts_edits store st.node)
| `Focus _ | `Caret _ -> false
in
if reject_edit then (st, [])
Comment on lines +334 to +340

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Read-only transitions retain active composition

When read-only activates during composition, feed_ime discards commits and cancellation reports without clearing marked text. Ui.handle suppresses keyboard handling while composition remains active. Existing tests cover initially read-only fields, leaving this reactive transition untested.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

else
let ime, actions = Lui_ime.feed_event st.ime ev in
let st, acts = apply_ime store { st with ime } actions in
(st, acts)

(* Model-side text sync — the revision protocol. The host's own
edits mirror into the store prop immediately, so a prop equal to
Expand Down
32 changes: 32 additions & 0 deletions platform/native/lui_input/test/lui_input_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,37 @@ let test_text_session () =
acts);
ignore store

let test_read_only_accepts_edits () =
let store =
store_of
[ CreateNode (1, TextField);
SetProp (1, TextValue, StringValue "ref");
SetProp (1, ReadOnly, BoolValue true) ]
in
Alcotest.(check bool) "editable for focus" true
(Lui_text_input.editable store 1);
Alcotest.(check bool) "rejects edits" false
(Lui_text_input.accepts_edits store 1);
let st = Lui_text_input.attach Lui_text_input.initial ~node:1 ~text:"ref" in
let st, acts = Lui_text_input.feed_ime store st (`Commit "x") in
Alcotest.(check string) "commit ignored" "ref" (Lui_text_input.text st);
Alcotest.(check bool) "no TextChanged" true
(not
(List.exists
(function `Dispatch (TextChanged _) -> true | _ -> false)
acts));
let rects = rects_of [ 1, rect 0. 0. 100. 20. ] in
let st, _ =
Lui_text_input.key hooks store rects st ~k:Lui_input.Backspace
~mods:none ~prim:false
in
Alcotest.(check string) "backspace ignored" "ref" (Lui_text_input.text st);
let st, _ =
Lui_text_input.key hooks store rects st ~k:Lui_input.Arrow_left
~mods:none ~prim:false
in
Alcotest.(check int) "navigation kept" 2 (Lui_text_input.caret st)

let test_unchanged_committed_replacement () =
let initial = Lui_text_input.attach Lui_text_input.initial ~node:4 ~text:"hello" in
let selected, _ = Lui_text_input.select_all initial in
Expand Down Expand Up @@ -1332,6 +1363,7 @@ let () =
( "text input",
[ Alcotest.test_case "navigation" `Quick test_text_navigation;
Alcotest.test_case "splice" `Quick test_text_session;
Alcotest.test_case "read-only" `Quick test_read_only_accepts_edits;
Alcotest.test_case "unchanged committed replacement" `Quick test_unchanged_committed_replacement;
Alcotest.test_case "undo" `Quick test_text_undo;
Alcotest.test_case "caret ops" `Quick test_text_caret_ops;
Expand Down
58 changes: 31 additions & 27 deletions platform/native/lui_layout/lui_layout.ml
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,10 @@ let vlist_state ctx id =
Hashtbl.replace ctx.vlists id v;
v

(* data-attrs is the wire-clean channel for virtual-list config that
the schema does not model: [data-item-extent] is the estimated row
main extent in logical px, [data-overscan] the extra rows mounted
past each viewport edge, [data-scroll-target]/[data-scroll-token]/
[data-scroll-anchor] the scroll-request triple and
[data-track-visible-range] the visible-range opt-in. *)
(* Legacy virtual-list config still rides [data-attrs]: typed
[item-extent]/[overscan] take precedence when present, then these
semantic attributes, then host defaults. Scroll-request and
visible-range opt-ins remain data-attrs-only for now. *)
let vlist_data_attr store id name =
match Lui_store.prop store id "data-attrs" with
| Some (StringValue s) -> (
Expand All @@ -976,9 +974,9 @@ let vlist_data_attr store id name =
let vlist_vertical store id =
pstr store id "orientation" <> Some "horizontal"

(* Pull the model inputs off the resolved style and the data-attrs.
[style] is the vlist's own flex style — padding, border and the
row gap come straight from it. *)
(* Pull the model inputs off the resolved style, typed props and the
data-attrs. [style] is the vlist's own flex style — padding, border
and the row gap come straight from it. *)
let vlist_configure ctx store (v : vlist) (style : Lui_flex.style) =
(* The logical child ids snapshot: [count] stays O(1) on the store,
but a per-row indexed probe on the intrusive child list is O(i),
Expand All @@ -989,28 +987,34 @@ let vlist_configure ctx store (v : vlist) (style : Lui_flex.style) =
let count = Lui_store.child_count store v.vid in
let gap = len_px ~owner:ctx.vh style.row_gap in
let estimate =
match
Option.bind
(vlist_data_attr store v.vid "data-item-extent")
(fun s -> float_of_string_opt (String.trim s))
with
match pnum store v.vid "item-extent" with
| Some f when f > 0. -> f *. ctx.scale
| _ -> (
match if count > 0 then v.kids.(0) else -1 with
| cid when cid >= 0 -> (
match pnum store cid "height" with
| Some h -> h *. ctx.scale
| None -> 28. *. ctx.scale)
| _ -> 28. *. ctx.scale)
match
Option.bind
(vlist_data_attr store v.vid "data-item-extent")
(fun s -> float_of_string_opt (String.trim s))
with
| Some f when f > 0. -> f *. ctx.scale
| _ -> (
match if count > 0 then v.kids.(0) else -1 with
| cid when cid >= 0 -> (
match pnum store cid "height" with
| Some h -> h *. ctx.scale
| None -> 28. *. ctx.scale)
| _ -> 28. *. ctx.scale))
in
let overscan =
match
Option.bind
(vlist_data_attr store v.vid "data-overscan")
(fun s -> int_of_string_opt (String.trim s))
with
| Some n -> max 0 n
| None -> 4
match Lui_store.int_prop store v.vid "overscan" with
| Some n when n >= 0 -> n
| _ -> (
match
Option.bind
(vlist_data_attr store v.vid "data-overscan")
(fun s -> int_of_string_opt (String.trim s))
with
| Some n -> max 0 n
| None -> 4)
in
(* Configure runs once per structural sync; child props may have
changed under a stable shape, so the lazy lookup indexes rebuild
Expand Down
13 changes: 7 additions & 6 deletions platform/native/lui_layout/lui_layout.mli
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ val sync :
content extent, so frame extent, scroll caps and hit clips behave
exactly as if all rows were laid out.

Config rides [data-attrs] on the node (no schema change):
[data-item-extent] — estimated row main extent in logical px (per-
child [height] or a 28px default otherwise); [data-overscan] —
extra rows mounted past each view edge (4 default). Rows are
measured once mounted, so a mixed-height list converges to real
positions; [data-scroll-target]/[data-scroll-token]/
Typed wire props [item-extent] (positive finite logical px) and
[overscan] (nonnegative row count) configure the estimate and mount
window. Legacy [data-item-extent]/[data-overscan] remain readable
when the typed props are absent; typed values take precedence.
Defaults are the first child's [height] or 28px, and overscan 4.
Rows are measured once mounted, so a mixed-height list converges
to real positions. [data-scroll-target]/[data-scroll-token]/
[data-scroll-anchor] name a scroll request the host resolves
through {!virtual_index_of_key}, and [data-track-visible-range]
opts the list into visible-range reports through {!virtual_view}. *)
Expand Down
51 changes: 51 additions & 0 deletions platform/native/lui_layout/test/lui_layout_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,56 @@ let test_vlist_mounted_children () =
check int "first id" (10 + f) (List.hd ids);
check int "last id" (10 + l - 1) (List.nth ids (l - f - 1))

(* Typed [overscan]/[item-extent] drive the mount window; legacy
data-attrs remain a fallback and lose to typed values. Row heights
match the configured estimate so measurement does not expand the
window mid-sync. *)
let test_vlist_typed_props () =
let store = vlist_store ~item_h:40. ~n:1000 () in
apply store
[ SetProp (2, VirtualOverscan, IntValue 0);
SetProp (2, VirtualItemExtent, FloatValue 40.) ];
let t = Lui_layout.create () in
Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800.
~vport:(vport 0. 200.) t store;
let f, l = Option.get (Lui_layout.mounted_range t 2) in
check int "typed overscan 0 first" 0 f;
(* 200px / 40px = 5 rows (+1 touching), no overscan past the end *)
check int "typed overscan 0 last" 6 l;
(* Legacy attributes alone still configure the estimate/window. *)
let legacy = vlist_store ~item_h:50. ~n:1000 () in
apply legacy
[ SetProp
(2, DataAttrs,
StringValue
(Lui_protocol.data_attrs_encode
[ ("data-item-extent", "50"); ("data-overscan", "1") ])) ];
let t = Lui_layout.create () in
Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800.
~vport:(vport 0. 200.) t legacy;
let f, l = Option.get (Lui_layout.mounted_range t 2) in
check int "legacy overscan first" 0 f;
(* 200/50 = 4 (+1) + 1 overscan → last 6 *)
check int "legacy overscan last" 6 l;
(* Typed props win over conflicting legacy attributes. Rebuild with
matching row heights so measurement does not widen the window. *)
let prefer = vlist_store ~item_h:100. ~n:1000 () in
apply prefer
[ SetProp
(2, DataAttrs,
StringValue
(Lui_protocol.data_attrs_encode
[ ("data-item-extent", "50"); ("data-overscan", "8") ]));
SetProp (2, VirtualOverscan, IntValue 0);
SetProp (2, VirtualItemExtent, FloatValue 100.) ];
let t = Lui_layout.create () in
Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800.
~vport:(vport 0. 200.) t prefer;
let f, l = Option.get (Lui_layout.mounted_range t 2) in
check int "typed wins first" 0 f;
(* 200/100 = 2 (+1), overscan 0 → last 3 (legacy overscan 8 ignored) *)
check int "typed wins last" 3 l

(* Variable heights settle through measured extents: overscan rows
above the anchor that differ from the estimate shift the prefix
sums — the drift the scroller folds back into the offset so the
Expand Down Expand Up @@ -2601,6 +2651,7 @@ let () =
test_case "vlist unwindowed" `Quick test_vlist_unwindowed;
test_case "vlist mounted children" `Quick
test_vlist_mounted_children;
test_case "vlist typed props" `Quick test_vlist_typed_props;
test_case "vlist anchor drift" `Quick test_vlist_anchor_drift;
test_case "vlist incremental child" `Quick
test_vlist_incremental_child;
Expand Down
18 changes: 18 additions & 0 deletions platform/native/lui_paint/lui_paint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ let prop_coverage =
("scroll-token", Host);
("scroll-animated", Host);
("track-visible-range", Host);
("overscan", Layout); (* virtual-list mount window *)
("item-extent", Layout); (* virtual-list row estimate *)
("virtual-total-count", Host); (* sparse virtual-list wire *)
("virtual-generation", Host);
("virtual-indices", Host);
("virtual-scroll-index", Host);
("virtual-viewport-epoch", Host);
("virtual-owner-node", Host);
("virtual-owner-epoch", Host);
("virtual-row-keys", Host);
("virtual-retentions", Host);
("virtual-retention-releases", Host);
("read-only", Host); (* text controls: focus/copy, reject edits *)
("pointer-capture", Host);
("indeterminate", Painted); (* checkbox mixed state *)
("toggle-detail-enabled", Host);
("focus-within-enabled", Host);
("shrink", Layout); (* flex shrink factor *)
("edge", Layout); (* edge-inset side *)
("request", Host); (* file picker *)
("types", Host);
Expand Down
10 changes: 3 additions & 7 deletions platform/native/lui_paint/test/lui_paint_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,6 @@ let test_secure_byte_of_masked () =

(* ---------- coverage ---------- *)

(* TODO: Restore this guard and its registration once the Native property
inventory accounts for read-only, overscan and item-extent.
let test_coverage_table () =
let names =
List.map Lui_wire_schema.property_name Lui_wire_schema.all_properties
Expand All @@ -1418,7 +1416,6 @@ let test_coverage_table () =
names
in
check bool "all props classified" true (missing = [])
*)

(* ---------- spatial index ---------- *)

Expand Down Expand Up @@ -2167,7 +2164,6 @@ let () =
test_case "build allocation" `Quick test_spatial_build_allocation;
test_case "paint equivalence" `Quick test_spatial_paint_equiv;
test_case "visit bound" `Quick test_spatial_visit_bound;
test_case "degenerate kept" `Quick test_spatial_degenerate_kept ])
(* TODO: Restore alongside test_coverage_table after the Native inventory update.
; ("coverage",
[ test_case "all props" `Quick test_coverage_table ]) *) ]
test_case "degenerate kept" `Quick test_spatial_degenerate_kept ]);
("coverage",
[ test_case "all props" `Quick test_coverage_table ]) ]
Loading
Loading