@native-sdk/cli 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/build/app.zig +50 -3
  2. package/build.zig +134 -360
  3. package/native-sdk.d.ts +4 -0
  4. package/package.json +9 -9
  5. package/packages/core/compile-surface/core.ts +90 -1
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/sdk/core.d.ts +65 -2
  9. package/packages/core/sdk/core.ts +189 -33
  10. package/packages/core/sdk/events.d.ts +14 -0
  11. package/packages/core/sdk/events.ts +18 -0
  12. package/packages/core/src/checker.ts +61 -1
  13. package/packages/core/src/devhost.ts +3 -3
  14. package/packages/core/src/diagnostics.ts +4 -4
  15. package/skill-data/core/SKILL.md +4 -2
  16. package/skill-data/core/references/project-anatomy.md +2 -1
  17. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  18. package/skill-data/native-ui/SKILL.md +8 -8
  19. package/skill-data/ts-core/SKILL.md +16 -13
  20. package/src/app_runner/app_assets.zig +138 -0
  21. package/src/app_runner/root.zig +2 -0
  22. package/src/app_runner/ts_core_main.zig +27 -3
  23. package/src/embed/host.zig +6 -0
  24. package/src/embed/ui_host.zig +2 -0
  25. package/src/platform/linux/root.zig +1 -0
  26. package/src/platform/macos/appkit_host.h +10 -0
  27. package/src/platform/macos/appkit_host.m +515 -93
  28. package/src/platform/macos/capture_info_plist.c +25 -0
  29. package/src/platform/macos/cef_host.mm +22 -0
  30. package/src/platform/macos/root.zig +68 -0
  31. package/src/platform/null_platform.zig +58 -0
  32. package/src/platform/root.zig +7 -0
  33. package/src/platform/types.zig +100 -0
  34. package/src/platform/windows/root.zig +56 -0
  35. package/src/platform/windows/webview2_host.cpp +171 -0
  36. package/src/primitives/app_manifest/types.zig +2 -0
  37. package/src/primitives/canvas/code_tests.zig +9 -9
  38. package/src/primitives/canvas/events.zig +12 -11
  39. package/src/primitives/canvas/frame.zig +44 -9
  40. package/src/primitives/canvas/icons/mic.svg +1 -0
  41. package/src/primitives/canvas/icons.zig +2 -0
  42. package/src/primitives/canvas/root.zig +8 -0
  43. package/src/primitives/canvas/text_span_tests.zig +39 -0
  44. package/src/primitives/canvas/ui.zig +23 -4
  45. package/src/primitives/canvas/ui_markup.zig +15 -0
  46. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  47. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  48. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  49. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  50. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  51. package/src/primitives/canvas/ui_schema.zig +19 -10
  52. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  53. package/src/primitives/canvas/ui_tests.zig +18 -4
  54. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  55. package/src/primitives/canvas/widget_render.zig +321 -115
  56. package/src/primitives/canvas/widget_runtime_tests.zig +173 -0
  57. package/src/primitives/canvas/widget_text_input.zig +10 -10
  58. package/src/primitives/canvas/widget_tree.zig +1 -1
  59. package/src/primitives/canvas/widgets.zig +41 -5
  60. package/src/root.zig +10 -0
  61. package/src/runtime/automation_widget_dispatch.zig +1 -0
  62. package/src/runtime/bridge_payload.zig +2 -0
  63. package/src/runtime/canvas_frame.zig +13 -2
  64. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  65. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  66. package/src/runtime/canvas_widget_event_tests.zig +1 -0
  67. package/src/runtime/canvas_widget_events.zig +69 -24
  68. package/src/runtime/canvas_widget_runtime.zig +101 -6
  69. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  70. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  71. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  72. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  73. package/src/runtime/canvas_widget_state.zig +10 -1
  74. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  75. package/src/runtime/effects.zig +313 -2
  76. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  77. package/src/runtime/root.zig +3 -0
  78. package/src/runtime/tests.zig +1 -0
  79. package/src/runtime/ts_core_host.zig +401 -32
  80. package/src/runtime/ts_core_host_tests.zig +407 -0
  81. package/src/runtime/ts_ui_app.zig +39 -1
  82. package/src/runtime/ui_app.zig +18 -3
  83. package/src/runtime/ui_app_tests.zig +48 -0
  84. package/src/runtime/view.zig +2 -0
  85. package/src/runtime/view_widget_scroll.zig +56 -5
  86. package/src/runtime/view_widget_text.zig +24 -5
  87. package/src/runtime/view_widget_tree.zig +1 -1
  88. package/src/tooling/manifest.zig +1034 -0
  89. package/src/tooling/package.zig +841 -10
  90. package/src/tooling/raw_manifest.zig +35 -0
  91. package/src/tooling/templates.zig +55 -0
  92. package/tools/corewire/emit_facade.zig +36 -0
@@ -372,6 +372,57 @@ test "tree keymap walks visible rows, collapses, expands, and selects through re
372
372
  try std.testing.expect(!after_enter.findById(12).?.widget.state.selected);
373
373
  }
374
374
 
375
+ test "tree roving focus only shows a ring after Tab entry" {
376
+ const harness = try TestHarness().create(std.testing.allocator, .{});
377
+ defer harness.destroy(std.testing.allocator);
378
+ harness.null_platform.gpu_surfaces = true;
379
+ var app_state: ObservingApp = .{};
380
+ const app = app_state.app();
381
+ try harness.start(app);
382
+
383
+ _ = try harness.runtime.createView(.{
384
+ .window_id = 1,
385
+ .label = "canvas",
386
+ .kind = .gpu_surface,
387
+ .frame = geometry.RectF.init(0, 0, 240, 100),
388
+ });
389
+
390
+ const rows = [_]canvas.Widget{
391
+ treeRowPanel(11, 0, 24, null, &.{}),
392
+ treeRowPanel(12, 30, 24, null, &.{}),
393
+ };
394
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
395
+ const layout = try canvas.layoutWidgetTree(
396
+ .{ .id = 10, .kind = .tree, .children = &rows },
397
+ geometry.RectF.init(0, 0, 240, 100),
398
+ &nodes,
399
+ );
400
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
401
+ const view = &harness.runtime.views[0];
402
+
403
+ // Pointer entry is quiet. Roving to the next row with ArrowDown
404
+ // must preserve that modality instead of flashing a focus ring
405
+ // before the selection echo rebuilds the tree.
406
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_down, .x = 10, .y = 10, .button = 0 } });
407
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_up, .x = 10, .y = 10, .button = 0 } });
408
+ try std.testing.expectEqual(@as(canvas.ObjectId, 11), view.canvas_widget_focused_id);
409
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), view.canvas_widget_focus_visible_id);
410
+
411
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
412
+ try std.testing.expectEqual(@as(canvas.ObjectId, 12), view.canvas_widget_focused_id);
413
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), view.canvas_widget_focus_visible_id);
414
+
415
+ // Tab is the explicit focus-visible entry. Once it establishes the
416
+ // ring, roving arrows carry that visible keyboard focus with them.
417
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab", .modifiers = .{ .shift = true } } });
418
+ try std.testing.expectEqual(@as(canvas.ObjectId, 11), view.canvas_widget_focused_id);
419
+ try std.testing.expectEqual(@as(canvas.ObjectId, 11), view.canvas_widget_focus_visible_id);
420
+
421
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
422
+ try std.testing.expectEqual(@as(canvas.ObjectId, 12), view.canvas_widget_focused_id);
423
+ try std.testing.expectEqual(@as(canvas.ObjectId, 12), view.canvas_widget_focus_visible_id);
424
+ }
425
+
375
426
  test "flat tree levels resolve logical parents and children" {
376
427
  const harness = try TestHarness().create(std.testing.allocator, .{});
377
428
  defer harness.destroy(std.testing.allocator);
@@ -537,6 +588,183 @@ test "a virtual list declaring the tree role scopes the tree keymap over its row
537
588
  try std.testing.expectEqual(@as(canvas.ObjectId, 23), view.canvas_widget_focused_id);
538
589
  }
539
590
 
591
+ test "tree arrow navigation reveals and focuses rows below a scroll viewport" {
592
+ const harness = try TestHarness().create(std.testing.allocator, .{});
593
+ defer harness.destroy(std.testing.allocator);
594
+ harness.null_platform.gpu_surfaces = true;
595
+ var app_state: ObservingApp = .{};
596
+ const app = app_state.app();
597
+ try harness.start(app);
598
+
599
+ _ = try harness.runtime.createView(.{
600
+ .window_id = 1,
601
+ .label = "canvas",
602
+ .kind = .gpu_surface,
603
+ .frame = geometry.RectF.init(0, 0, 240, 64),
604
+ });
605
+
606
+ const rows = [_]canvas.Widget{
607
+ treeRowPanel(21, 0, 28, null, &.{}),
608
+ treeRowPanel(22, 0, 28, null, &.{}),
609
+ treeRowPanel(23, 0, 28, null, &.{}),
610
+ treeRowPanel(24, 0, 28, null, &.{}),
611
+ };
612
+ const tree = canvas.Widget{
613
+ .id = 20,
614
+ .kind = .tree,
615
+ .frame = geometry.RectF.init(0, 0, 0, 118),
616
+ .layout = .{ .gap = 2 },
617
+ .children = &rows,
618
+ };
619
+ const root = canvas.Widget{
620
+ .id = 10,
621
+ .kind = .scroll_view,
622
+ .children = &.{tree},
623
+ };
624
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
625
+ const layout = try canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 64), &nodes);
626
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
627
+ const view = &harness.runtime.views[0];
628
+
629
+ // Row 2 is fully visible and row 3 has only its leading 4pt inside
630
+ // the viewport. Focus row 2 by pointer, then walk onto row 3.
631
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_down, .x = 10, .y = 40, .button = 0 } });
632
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_up, .x = 10, .y = 40, .button = 0 } });
633
+ try std.testing.expectEqual(@as(canvas.ObjectId, 22), view.canvas_widget_focused_id);
634
+
635
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
636
+ try std.testing.expectEqual(@as(canvas.ObjectId, 23), view.canvas_widget_focused_id);
637
+
638
+ // The next logical row starts fully below the clip. ArrowDown must
639
+ // minimally scroll it into view, move focus, and route the keyboard
640
+ // selection arrival to that newly visible row.
641
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
642
+ try std.testing.expectEqual(@as(canvas.ObjectId, 24), view.canvas_widget_focused_id);
643
+ try std.testing.expectEqual(@as(canvas.ObjectId, 24), app_state.last_keyboard_target_id);
644
+ try std.testing.expect(app_state.last_keyboard_focus_moved);
645
+
646
+ const scrolled = try harness.runtime.canvasWidgetLayout(1, "canvas");
647
+ const viewport = scrolled.findById(10).?.frame.normalized();
648
+ const focused = scrolled.findById(24).?.frame.normalized();
649
+ try std.testing.expect(focused.y >= viewport.y);
650
+ try std.testing.expect(focused.maxY() <= viewport.maxY());
651
+ try std.testing.expect(scrolled.findById(10).?.widget.value > 0);
652
+ }
653
+
654
+ test "list arrow navigation reveals and focuses rows below a scroll viewport" {
655
+ const harness = try TestHarness().create(std.testing.allocator, .{});
656
+ defer harness.destroy(std.testing.allocator);
657
+ harness.null_platform.gpu_surfaces = true;
658
+ var app_state: ObservingApp = .{};
659
+ const app = app_state.app();
660
+ try harness.start(app);
661
+
662
+ _ = try harness.runtime.createView(.{
663
+ .window_id = 1,
664
+ .label = "canvas",
665
+ .kind = .gpu_surface,
666
+ .frame = geometry.RectF.init(0, 0, 240, 64),
667
+ });
668
+
669
+ const rows = [_]canvas.Widget{
670
+ .{ .id = 31, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 28), .text = "One" },
671
+ .{ .id = 32, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 28), .text = "Two" },
672
+ .{ .id = 33, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 28), .text = "Three" },
673
+ .{ .id = 34, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 28), .text = "Four" },
674
+ };
675
+ const list = canvas.Widget{
676
+ .id = 30,
677
+ .kind = .list,
678
+ .frame = geometry.RectF.init(0, 0, 0, 118),
679
+ .layout = .{ .gap = 2 },
680
+ .children = &rows,
681
+ };
682
+ const root = canvas.Widget{
683
+ .id = 10,
684
+ .kind = .scroll_view,
685
+ .children = &.{list},
686
+ };
687
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
688
+ const layout = try canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 64), &nodes);
689
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
690
+ try harness.runtime.focusView(1, "canvas");
691
+ const view = &harness.runtime.views[0];
692
+
693
+ // Keyboard entry grants the list-row roving contract (pointer focus
694
+ // stays intentionally quiet). The first Tab focuses the scroll view,
695
+ // the second reaches row 1.
696
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
697
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
698
+ try std.testing.expectEqual(@as(canvas.ObjectId, 31), view.canvas_widget_focused_id);
699
+
700
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
701
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
702
+ try std.testing.expectEqual(@as(canvas.ObjectId, 33), view.canvas_widget_focused_id);
703
+
704
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
705
+ try std.testing.expectEqual(@as(canvas.ObjectId, 34), view.canvas_widget_focused_id);
706
+
707
+ const scrolled = try harness.runtime.canvasWidgetLayout(1, "canvas");
708
+ const viewport = scrolled.findById(10).?.frame.normalized();
709
+ const focused = scrolled.findById(34).?.frame.normalized();
710
+ try std.testing.expect(focused.y >= viewport.y);
711
+ try std.testing.expect(focused.maxY() <= viewport.maxY());
712
+ try std.testing.expect(scrolled.findById(10).?.widget.value > 0);
713
+ }
714
+
715
+ test "tree arrow navigation refuses rows clipped without a scroll ancestor" {
716
+ const harness = try TestHarness().create(std.testing.allocator, .{});
717
+ defer harness.destroy(std.testing.allocator);
718
+ harness.null_platform.gpu_surfaces = true;
719
+ var app_state: ObservingApp = .{};
720
+ const app = app_state.app();
721
+ try harness.start(app);
722
+
723
+ _ = try harness.runtime.createView(.{
724
+ .window_id = 1,
725
+ .label = "canvas",
726
+ .kind = .gpu_surface,
727
+ .frame = geometry.RectF.init(0, 0, 240, 64),
728
+ });
729
+
730
+ const rows = [_]canvas.Widget{
731
+ treeRowPanel(21, 0, 28, null, &.{}),
732
+ treeRowPanel(22, 0, 28, null, &.{}),
733
+ treeRowPanel(23, 0, 28, null, &.{}),
734
+ treeRowPanel(24, 0, 28, null, &.{}),
735
+ };
736
+ const tree = canvas.Widget{
737
+ .id = 20,
738
+ .kind = .tree,
739
+ .frame = geometry.RectF.init(0, 0, 0, 118),
740
+ .layout = .{ .gap = 2 },
741
+ .children = &rows,
742
+ };
743
+ const root = canvas.Widget{
744
+ .id = 10,
745
+ .kind = .stack,
746
+ .layout = .{ .clip_content = true },
747
+ .children = &.{tree},
748
+ };
749
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
750
+ const layout = try canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 64), &nodes);
751
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
752
+ const view = &harness.runtime.views[0];
753
+
754
+ // Row 3 intersects the fixed clip, but row 4 is completely outside it.
755
+ // Without a scroll ancestor the logical successor cannot be revealed,
756
+ // so the final ArrowDown must leave focus on the last visible row.
757
+ try std.testing.expect(layout.focusTargetById(24) == null);
758
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_down, .x = 10, .y = 40, .button = 0 } });
759
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_up, .x = 10, .y = 40, .button = 0 } });
760
+ try std.testing.expectEqual(@as(canvas.ObjectId, 22), view.canvas_widget_focused_id);
761
+
762
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
763
+ try std.testing.expectEqual(@as(canvas.ObjectId, 23), view.canvas_widget_focused_id);
764
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowdown" } });
765
+ try std.testing.expectEqual(@as(canvas.ObjectId, 23), view.canvas_widget_focused_id);
766
+ }
767
+
540
768
  // ------------------------------------------------------- layout tweens
541
769
 
542
770
  /// Install the standard 0.5 split on a fresh gpu-surface view and
@@ -32,7 +32,7 @@ fn canvasWidgetLayoutNeedsLargeTextStorage(layout: canvas.WidgetLayoutTree) bool
32
32
  var text_len: usize = 0;
33
33
  for (layout.nodes) |node| {
34
34
  const widget = node.widget;
35
- if (widget.code_editor) return true;
35
+ if (widget.runtime_flags.code_editor) return true;
36
36
  text_len +|= widget.text.len +| widget.icon.len +| widget.command.len +| widget.semantics.label.len;
37
37
  for (widget.spans) |span| text_len +|= span.text.len +| span.link.len;
38
38
  for (widget.context_menu) |item| text_len +|= item.label.len;
@@ -185,6 +185,11 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
185
185
  try self.views[index].copyCanvasWidgetSourceText(layout);
186
186
  self.views[index].copyCanvasWidgetSourceScroll(layout);
187
187
  self.views[index].copyCanvasWidgetSourceControls(layout);
188
+ // A controlled text replacement (the common submit-and-clear
189
+ // composer flow) drops stale selection state while retaining
190
+ // logical focus. Re-establish the insertion point before this
191
+ // rebuild emits so the caret never disappears until typing.
192
+ _ = try self.views[index].ensureCanvasWidgetFocusedTextCaret();
188
193
  // Push the reconciled regions (frames, content extents,
189
194
  // diverged offsets) to the native scroll drivers.
190
195
  ScrollDriverMethods(Runtime).syncCanvasWidgetScrollDriversForView(self, index);
@@ -564,6 +569,10 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
564
569
  .id = id,
565
570
  .from_offset = offset,
566
571
  .offset = offset,
572
+ // The terminal source replaces a window-level floating
573
+ // preview, so keep it above both its old and new lane's
574
+ // clips until it reaches the committed slot.
575
+ .escape_ancestor_clips = view.canvas_widget_drag_landing_source_id == id,
567
576
  .duration_ms = duration_ms,
568
577
  .easing = .emphasized,
569
578
  .spring = view.widget_tokens.motion.spring,
@@ -109,7 +109,7 @@ test "closing an earlier view transfers a later view's expanded text storage" {
109
109
  .kind = .textarea,
110
110
  .text = "expanded",
111
111
  .text_no_wrap = true,
112
- .code_editor = true,
112
+ .runtime_flags = .{ .code_editor = true },
113
113
  };
114
114
  var editor_nodes: [1]canvas.WidgetLayoutNode = undefined;
115
115
  const editor_layout = try canvas.layoutWidgetTree(editor, geometry.RectF.init(0, 0, 240, 160), &editor_nodes);
@@ -2298,6 +2298,115 @@ test "plain Enter inserts a newline in a canvas textarea; chorded Enter never ed
2298
2298
  } });
2299
2299
  retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2300
2300
  try std.testing.expectEqualStrings("First\n", retained.nodes[1].widget.text);
2301
+
2302
+ // The chat-composer policy leaves plain Enter for the UI submit
2303
+ // handler, so retained text does not receive a newline. Shift+Enter
2304
+ // remains an edit and inserts one exactly as the default textarea
2305
+ // does.
2306
+ const prompt = canvas.Widget{
2307
+ .id = 2,
2308
+ .kind = .textarea,
2309
+ .frame = geometry.RectF.init(12, 16, 180, 84),
2310
+ .text = "Prompt",
2311
+ .submit_on_enter = true,
2312
+ .semantics = .{ .label = "Message" },
2313
+ };
2314
+ var prompt_nodes: [2]canvas.WidgetLayoutNode = undefined;
2315
+ const prompt_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{prompt} }, geometry.RectF.init(0, 0, 260, 160), &prompt_nodes);
2316
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", prompt_layout);
2317
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2318
+ .window_id = 1,
2319
+ .label = "canvas",
2320
+ .kind = .key_down,
2321
+ .key = "enter",
2322
+ } });
2323
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2324
+ try std.testing.expectEqualStrings("Prompt", retained.nodes[1].widget.text);
2325
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2326
+ .window_id = 1,
2327
+ .label = "canvas",
2328
+ .kind = .key_down,
2329
+ .key = "enter",
2330
+ .modifiers = .{ .shift = true },
2331
+ } });
2332
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2333
+ try std.testing.expectEqualStrings("Prompt\n", retained.nodes[1].widget.text);
2334
+ }
2335
+
2336
+ test "focused textarea keeps a visible caret when controlled source clears after submit" {
2337
+ const TestApp = struct {
2338
+ fn app(self: *@This()) App {
2339
+ return .{ .context = self, .name = "gpu-widget-textarea-submit-clear", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
2340
+ }
2341
+ };
2342
+
2343
+ const harness = try TestHarness().create(std.testing.allocator, .{});
2344
+ defer harness.destroy(std.testing.allocator);
2345
+ harness.null_platform.gpu_surfaces = true;
2346
+ var app_state: TestApp = .{};
2347
+ const app = app_state.app();
2348
+ try harness.start(app);
2349
+
2350
+ _ = try harness.runtime.createView(.{
2351
+ .window_id = 1,
2352
+ .label = "canvas",
2353
+ .kind = .gpu_surface,
2354
+ .frame = geometry.RectF.init(0, 0, 260, 160),
2355
+ });
2356
+
2357
+ const prompt = canvas.Widget{
2358
+ .id = 2,
2359
+ .kind = .textarea,
2360
+ .frame = geometry.RectF.init(12, 16, 180, 84),
2361
+ .text = "Prompt",
2362
+ .submit_on_enter = true,
2363
+ .semantics = .{ .label = "Message" },
2364
+ };
2365
+ var prompt_nodes: [2]canvas.WidgetLayoutNode = undefined;
2366
+ const prompt_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{prompt} }, geometry.RectF.init(0, 0, 260, 160), &prompt_nodes);
2367
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", prompt_layout);
2368
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
2369
+
2370
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2371
+ .window_id = 1,
2372
+ .label = "canvas",
2373
+ .kind = .pointer_down,
2374
+ .x = 100,
2375
+ .y = 30,
2376
+ } });
2377
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2378
+ .window_id = 1,
2379
+ .label = "canvas",
2380
+ .kind = .key_down,
2381
+ .key = "enter",
2382
+ } });
2383
+
2384
+ var cleared_prompt = prompt;
2385
+ cleared_prompt.text = "";
2386
+ var cleared_nodes: [2]canvas.WidgetLayoutNode = undefined;
2387
+ const cleared_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{cleared_prompt} }, geometry.RectF.init(0, 0, 260, 160), &cleared_nodes);
2388
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", cleared_layout);
2389
+
2390
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2391
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
2392
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
2393
+ try std.testing.expectEqualStrings("", retained.nodes[1].widget.text);
2394
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), retained.nodes[1].widget.text_selection.?);
2395
+ try std.testing.expectEqualDeep(canvas.TextRange.init(0, 0), runtimeViewWidgetSemantics(&harness.runtime.views[0])[0].text_selection.?);
2396
+
2397
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
2398
+ const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
2399
+ var saw_caret = false;
2400
+ for (display_list.commands) |command| {
2401
+ switch (command) {
2402
+ .fill_rect => |fill| {
2403
+ if (fill.id == testCanvasWidgetPartId(2, 6)) saw_caret = true;
2404
+ },
2405
+ else => {},
2406
+ }
2407
+ }
2408
+ try std.testing.expect(saw_caret);
2409
+ try std.testing.expectEqual(testCanvasWidgetPartId(2, 6), harness.runtime.views[0].canvas_widget_caret_blink_id);
2301
2410
  }
2302
2411
 
2303
2412
  test "Enter in a single-line input never inserts, even when the host stuffs a newline into the key event" {
@@ -3906,7 +4015,7 @@ test "editable code owns plain Tab and stamps its inferred indentation edit" {
3906
4015
  .{
3907
4016
  .id = 2,
3908
4017
  .kind = .textarea,
3909
- .code_editor = true,
4018
+ .runtime_flags = .{ .code_editor = true },
3910
4019
  .text_no_wrap = true,
3911
4020
  .frame = geometry.RectF.init(12, 16, 220, 100),
3912
4021
  .text = source,
@@ -4620,7 +4729,7 @@ test "runtime scrolls editable no-wrap code horizontally and retains both axes"
4620
4729
  const editor = canvas.Widget{
4621
4730
  .id = 2,
4622
4731
  .kind = .textarea,
4623
- .code_editor = true,
4732
+ .runtime_flags = .{ .code_editor = true },
4624
4733
  .code_line_number_digits = 2,
4625
4734
  .text_no_wrap = true,
4626
4735
  .frame = geometry.RectF.init(12, 16, 120, 72),