@native-sdk/cli 0.5.3 → 0.6.0

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 (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -81,10 +81,11 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
81
81
 
82
82
  /// The press target a routed pointer event dispatches to, with the
83
83
  /// press-vs-drag disambiguation applied: a release that ends a
84
- /// static-text selection drag is a selection gesture, not a click,
85
- /// so it presses no one (the selection it made stays live for
86
- /// copy). A plain click collapses the selection on `.down`, so it
87
- /// reaches `.up` collapsed and the press lands normally.
84
+ /// static-text or terminal selection drag is a selection
85
+ /// gesture, not a click, so it presses no one (the selection it
86
+ /// made stays live for copy). A plain click collapses the
87
+ /// selection on `.down`, so it reaches `.up` collapsed and the
88
+ /// press lands normally.
88
89
  fn canvasWidgetPressTargetForRoute(
89
90
  self: *const Runtime,
90
91
  view_index: usize,
@@ -94,6 +95,12 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
94
95
  const press_target = route.press_target orelse return null;
95
96
  if (pointer.phase != .up) return press_target;
96
97
  const raw = route.target orelse return press_target;
98
+ if (raw.kind == .terminal) {
99
+ const node = self.views[view_index].widgetLayoutTree().findById(raw.id) orelse return press_target;
100
+ const grid = node.widget.terminal.grid orelse return press_target;
101
+ if (grid.selection_active) return null;
102
+ return press_target;
103
+ }
97
104
  if (raw.kind != .text) return press_target;
98
105
  if (self.views[view_index].canvas_widget_selected_text_id != raw.id) return press_target;
99
106
  const node = self.views[view_index].widgetLayoutTree().findById(raw.id) orelse return press_target;
@@ -186,11 +193,42 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
186
193
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
187
194
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
188
195
  if (!self.views[index].focused) return null;
189
- const focused_id = self.views[index].canvas_widget_focused_id;
190
- if (focused_id == 0) return null;
191
- const keyboard = canvasWidgetTextInputEventFromGpuInput(input_event, focused_id) orelse return null;
196
+ const tree = self.views[index].widgetLayoutTree();
197
+ // An open IME sequence belongs to the editor it STARTED in:
198
+ // its set/commit/cancel continue to route to the owning
199
+ // text entry even when keyboard focus has since moved, so
200
+ // the starting editor resolves its own marked text — never
201
+ // the newly focused widget, never the target-less fallback.
202
+ // `text_input` prefers the owner too: the owner pin is only
203
+ // ever set mid-sequence (and held one event past a cancel,
204
+ // the converted-commit grace), and in both windows a
205
+ // text_input is the sequence's own resolution — the hosts
206
+ // never deliver ordinary typing while a composition is open.
207
+ const ime_owner = self.views[index].canvas_widget_ime_owner_id;
208
+ const target_id = switch (input_event.kind) {
209
+ .ime_set_composition, .ime_commit_composition, .ime_cancel_composition, .text_input => id: {
210
+ if (ime_owner != 0) {
211
+ if (tree.findById(ime_owner)) |node| {
212
+ if (canvas.isWidgetTextEntry(node.widget)) break :id ime_owner;
213
+ }
214
+ }
215
+ break :id self.views[index].canvas_widget_focused_id;
216
+ },
217
+ else => self.views[index].canvas_widget_focused_id,
218
+ };
219
+ if (target_id == 0) return null;
220
+ // Text and IME only belong to an EDITABLE widget. A focused
221
+ // non-text widget (a button, a list row) cannot consume a
222
+ // composition, so returning null here lets the committed
223
+ // text fall through to the app's target-less `on_text` seam
224
+ // instead of being routed to a widget that drops it — the
225
+ // terminal-with-a-focused-button case.
226
+ if (tree.findById(target_id)) |node| {
227
+ if (!canvas.isWidgetTextEntry(node.widget)) return null;
228
+ }
229
+ const keyboard = canvasWidgetTextInputEventFromGpuInput(input_event, target_id) orelse return null;
192
230
 
193
- const route = try self.views[index].widgetLayoutTree().routeKeyboardEvent(keyboard, output);
231
+ const route = try tree.routeKeyboardEvent(keyboard, output);
194
232
  if (route.target == null) return null;
195
233
  return .{
196
234
  .window_id = input_event.window_id,
@@ -333,7 +371,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
333
371
  // caret) however focus arrived — the :focus-visible contract
334
372
  // text inputs have on every platform.
335
373
  const next_focus_visible_id: canvas.ObjectId = if (pointer_event.press_target) |target| blk: {
336
- if (target.id == next_focus_id and canvas_widget_runtime.canvasWidgetEditableTextKind(target.kind)) break :blk next_focus_id;
374
+ if (target.id == next_focus_id and canvas_widget_runtime.canvasWidgetShowsPointerFocusRing(target.kind)) break :blk next_focus_id;
337
375
  break :blk 0;
338
376
  } else 0;
339
377
 
@@ -366,34 +404,122 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
366
404
  const target_id: canvas.ObjectId = if (pointer_event.target) |target| target.id else 0;
367
405
  const hover_target = layout_tree.hoverTargetForHit(pointer_event.target);
368
406
  const hover_target_id: canvas.ObjectId = if (hover_target) |value| value.id else 0;
369
- const hit_target = layout_tree.hoverTargetForHit(layout_tree.hitTestWithTokens(pointer_event.pointer.point, self.views[index].widget_tokens));
407
+ const raw_hit = layout_tree.hitTestWithTokens(pointer_event.pointer.point, self.views[index].widget_tokens);
408
+ // Containment resolves through the HOVER policy hit test —
409
+ // the only consumer that may see hover-only listeners; the
410
+ // wash/cursor resolution below stays on the interactive
411
+ // raw hit, so binding hover never moves a wash or a click.
412
+ const hover_raw_hit = layout_tree.hitTestHoverWithTokens(pointer_event.pointer.point, self.views[index].widget_tokens);
413
+ const hit_target = layout_tree.hoverTargetForHit(raw_hit);
370
414
  const hit_target_id: canvas.ObjectId = if (hit_target) |value| value.id else 0;
371
415
  const hit_cursor = platformCursorFromCanvas(layout_tree.cursorForHit(hit_target));
372
416
  var next_hovered_id = self.views[index].canvas_widget_hovered_id;
373
417
  var next_pressed_id = self.views[index].canvas_widget_pressed_id;
374
418
  var next_cursor = self.views[index].canvas_widget_cursor;
375
419
 
420
+ // The hover-Msg chain re-resolves from the SAME raw hit the
421
+ // wash phase-switch consumes below, so containment and the
422
+ // wash always agree: fresh hit test for hovers/moves/ups
423
+ // (drags included — the wash follows the actual pointer),
424
+ // the routed raw target for downs, empty on cancel (the
425
+ // pointer left the view — the window-leave edge). Wheel
426
+ // keeps the standing chain; the scroll reconcile re-derives
427
+ // it from the post-scroll tree. Down/drag/up advance the
428
+ // chain only while a hover-capable pointer is live (a prior
429
+ // hover-phase move) — touch input arrives as bare
430
+ // down/drag/up sequences, so a tap or a scrub can never
431
+ // synthesize hover, while a mouse (whose presence the
432
+ // hover phase already proved) keeps full fidelity through
433
+ // clicks and drags.
434
+ // The hover-capable proof is per pointer IDENTITY: only the
435
+ // pointer that earned it (a hover-phase move) advances the
436
+ // chain through its clicks and drags, so on hosts that
437
+ // distinguish pointers a touch contact can never ride a
438
+ // mouse's proof.
439
+ const hover_pointer_proven = self.views[index].canvas_widget_hover_pointer_live and
440
+ self.views[index].canvas_widget_hover_pointer_id == pointer_event.pointer.pointer_id;
376
441
  switch (pointer_event.pointer.phase) {
377
442
  .hover, .move => {
378
443
  next_hovered_id = hit_target_id;
379
444
  next_cursor = hit_cursor;
445
+ // A hover-phase move earns the proof UNLESS the host
446
+ // stamped the event touch-sourced
447
+ // (`platform.touch_pointer_id_bit`): Windows
448
+ // synthesizes a mouse-shaped move for every tap, and
449
+ // that fake float must never make touch hoverable.
450
+ const touch_sourced = pointer_event.pointer.pointer_id & platform.touch_pointer_id_bit != 0;
451
+ if (pointer_event.pointer.phase == .hover and !touch_sourced) {
452
+ self.views[index].canvas_widget_hover_pointer_live = true;
453
+ self.views[index].canvas_widget_hover_pointer_id = pointer_event.pointer.pointer_id;
454
+ self.views[index].canvas_widget_hover_pointer_position = pointer_event.pointer.point;
455
+ self.views[index].setCanvasWidgetHoverMsgChainForHit(hover_raw_hit);
456
+ } else if (hover_pointer_proven) {
457
+ self.views[index].canvas_widget_hover_pointer_position = pointer_event.pointer.point;
458
+ self.views[index].setCanvasWidgetHoverMsgChainForHit(hover_raw_hit);
459
+ }
380
460
  },
381
461
  .down => {
382
462
  next_hovered_id = hover_target_id;
383
463
  next_pressed_id = target_id;
384
464
  next_cursor = platformCursorFromCanvas(layout_tree.cursorForHit(hover_target));
465
+ if (hover_pointer_proven) {
466
+ self.views[index].canvas_widget_hover_pointer_position = pointer_event.pointer.point;
467
+ // The down's routed target is interactive-only;
468
+ // containment keeps its own resolution.
469
+ self.views[index].setCanvasWidgetHoverMsgChainForHit(hover_raw_hit);
470
+ }
385
471
  },
386
472
  .up => {
387
473
  next_hovered_id = hit_target_id;
388
474
  next_pressed_id = 0;
389
475
  next_cursor = hit_cursor;
476
+ if (hover_pointer_proven) {
477
+ if (geometry.RectF.fromSize(self.views[index].gpu_size).containsPoint(pointer_event.pointer.point)) {
478
+ self.views[index].canvas_widget_hover_pointer_position = pointer_event.pointer.point;
479
+ self.views[index].setCanvasWidgetHoverMsgChainForHit(hover_raw_hit);
480
+ } else {
481
+ // A captured release OUTSIDE the surface is
482
+ // the pointer already gone — the leave the
483
+ // press suppressed: hosts hold a grab
484
+ // through the drag (no motion-leave fired)
485
+ // and send no later cancel, so containment
486
+ // must retire here or an overflowing
487
+ // listener stays entered at an off-view
488
+ // point — and the anchor must not park
489
+ // off-view for a later rebuild to re-hit.
490
+ // The consumed secondary release has the
491
+ // same rule in gpu_surface_events.
492
+ self.views[index].canvas_widget_hover_msg_chain_len = 0;
493
+ self.views[index].canvas_widget_hover_pointer_live = false;
494
+ }
495
+ }
390
496
  },
391
497
  .cancel => {
392
498
  next_hovered_id = 0;
393
499
  next_pressed_id = 0;
394
500
  next_cursor = .arrow;
501
+ // Only the proven pointer's departure retires the
502
+ // containment (a lifted touch finger's cancel must
503
+ // not clear a mouse's standing hover); a cancel
504
+ // before any proof clears nothing because nothing
505
+ // stands.
506
+ if (hover_pointer_proven) {
507
+ self.views[index].canvas_widget_hover_msg_chain_len = 0;
508
+ self.views[index].canvas_widget_hover_pointer_live = false;
509
+ }
510
+ },
511
+ .wheel => {
512
+ // The proven pointer's wheel carries its CURRENT
513
+ // position: refresh the chain's re-hit anchor before
514
+ // the scroll reconcile resolves against it, so a
515
+ // wheel arriving ahead of its coalesced motion event
516
+ // still derives containment from where the pointer
517
+ // really is (the wash resolves from this same wheel
518
+ // point).
519
+ if (hover_pointer_proven) {
520
+ self.views[index].canvas_widget_hover_pointer_position = pointer_event.pointer.point;
521
+ }
395
522
  },
396
- .wheel => {},
397
523
  }
398
524
 
399
525
  // Hover-detail chrome (chart cursor + floating card) tracks
@@ -1647,7 +1773,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1647
1773
  // live tokens, so the dirty region must measure the same way.
1648
1774
  const local_dirty = self.views[view_index].widgetLayoutTree().renderStateDirtyBoundsWithTokens(previous, next, self.views[view_index].widget_tokens);
1649
1775
  invalidateForCanvasWidgetRenderStateDirty(self, view_index, local_dirty);
1650
- const publish_accessibility = previous.focused_id != next.focused_id;
1776
+ const publish_accessibility = previous.focused_id != next.focused_id or previous.keyboard_active != next.keyboard_active;
1651
1777
  _ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwnedWithAccessibility(self, view_index, publish_accessibility);
1652
1778
  }
1653
1779
 
@@ -1665,6 +1791,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1665
1791
  pub fn canvasWidgetRenderStateAfterLayout(previous: canvas.WidgetRenderState, layout: canvas.WidgetLayoutTree) canvas.WidgetRenderState {
1666
1792
  const next_focused_id = if (previous.focused_id) |id| if (layout.focusTargetById(id) != null) id else null else null;
1667
1793
  return .{
1794
+ .keyboard_active = previous.keyboard_active,
1668
1795
  .focused_id = next_focused_id,
1669
1796
  .focus_visible_id = if (previous.focus_visible_id) |id| if (next_focused_id != null and next_focused_id.? == id and layout.focusTargetById(id) != null) id else null else null,
1670
1797
  .hovered_id = if (previous.hovered_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
@@ -1676,7 +1803,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1676
1803
  }
1677
1804
 
1678
1805
  pub fn canvasWidgetRenderStatesEqual(a: canvas.WidgetRenderState, b: canvas.WidgetRenderState) bool {
1679
- return a.focused_id == b.focused_id and
1806
+ return a.keyboard_active == b.keyboard_active and
1807
+ a.focused_id == b.focused_id and
1680
1808
  a.focus_visible_id == b.focus_visible_id and
1681
1809
  a.hovered_id == b.hovered_id and
1682
1810
  a.pressed_id == b.pressed_id and
@@ -1775,7 +1903,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1775
1903
  const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
1776
1904
  if (self.views[index].kind != .gpu_surface) return;
1777
1905
 
1778
- const dirty = try self.views[index].applyCanvasWidgetScrollRoute(pointer_event.route, pointer_event.pointer.delta.dy, .wheel) orelse return;
1906
+ const dirty = try self.views[index].applyCanvasWidgetScrollRoute(pointer_event.route, pointer_event.pointer.delta, .wheel) orelse return;
1779
1907
  const previous_cursor = self.views[index].canvas_widget_cursor;
1780
1908
  try reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent(self, index, pointer_event.pointer.point);
1781
1909
  if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
@@ -1796,12 +1924,13 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1796
1924
  /// - cut: copy, then stamp a delete-selection edit onto the routed
1797
1925
  /// keyboard event so runtime widget and app model apply the same
1798
1926
  /// removal.
1799
- /// - paste: reads the clipboard into `paste_buffer`, sanitizes it
1800
- /// for the target kind and THEN clamps to the view's text
1801
- /// capacity (setting `edit_truncated` loudly) — order matters:
1802
- /// clamping first would spend capacity on line-break bytes the
1803
- /// seam strips anyway — and stamps the insertion onto the
1804
- /// routed keyboard event.
1927
+ /// - paste: a terminal target becomes provenance-tagged committed
1928
+ /// input for its dedicated VT paste encoder; editable text reads
1929
+ /// the clipboard into `paste_buffer`, sanitizes it for the target
1930
+ /// kind and THEN clamps to the view's text capacity (setting
1931
+ /// `edit_truncated` loudly) — order matters: clamping first would
1932
+ /// spend capacity on line-break bytes the seam strips anyway —
1933
+ /// and stamps the insertion onto the routed keyboard event.
1805
1934
  ///
1806
1935
  /// Platforms without a clipboard capability report
1807
1936
  /// `UnsupportedService`; the shortcut degrades to a no-op instead
@@ -1840,6 +1969,28 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1840
1969
  const target = event.target orelse return;
1841
1970
  const node_index = self.views[index].canvasWidgetNodeIndexById(target.id) orelse return;
1842
1971
  const widget = self.views[index].widget_layout_nodes[node_index].widget;
1972
+ if (widget.kind == .terminal and !widget.state.disabled and widget.terminal.pty != 0) {
1973
+ // A terminal paste is committed input, but it must
1974
+ // stay distinct from typing: the session's paste
1975
+ // encoder owns bracketed-paste framing, newline
1976
+ // conversion, and unsafe-control stripping. Shape
1977
+ // the shortcut exactly like context-menu Paste.
1978
+ const focused_id = event.keyboard.focused_id;
1979
+ event.keyboard = .{ .phase = .text_input, .focused_id = focused_id };
1980
+ event.terminal_paste = true;
1981
+ self.views[index].canvas_widget_terminal_paste_v_held = true;
1982
+
1983
+ // Mark the shortcut as consumed before touching
1984
+ // the clipboard. An unavailable/empty clipboard
1985
+ // must not turn Cmd+V into a key sent to the child.
1986
+ const grid = widget.terminal.grid orelse return;
1987
+ if (!grid.running) return;
1988
+ const text = self.readClipboard(paste_buffer) catch return;
1989
+ if (text.len == 0) return;
1990
+ event.keyboard.text = text;
1991
+ event.keyboard.edit = .{ .insert_text = text };
1992
+ return;
1993
+ }
1843
1994
  if (!canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return;
1844
1995
  // An empty or unavailable clipboard pastes nothing.
1845
1996
  const text = self.readClipboard(paste_buffer) catch return;
@@ -2162,6 +2313,40 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2162
2313
  try dispatchCanvasWidgetCommandForId(self, app, index, target.id);
2163
2314
  }
2164
2315
 
2316
+ /// Returns true for an auto-repeat or release belonging to the
2317
+ /// physical Tab gesture that moved focus into a live terminal.
2318
+ /// The caller suppresses that transition; the release also
2319
+ /// retires the gesture latch.
2320
+ pub fn consumeCanvasWidgetTerminalFocusEntryTab(self: *Runtime, input_event: GpuSurfaceInputEvent) bool {
2321
+ if (input_event.kind != .key_down and input_event.kind != .key_up) return false;
2322
+ if (!std.ascii.eqlIgnoreCase(input_event.key, "tab")) return false;
2323
+ const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
2324
+ if (self.views[index].kind != .gpu_surface) return false;
2325
+ if (!self.views[index].canvas_widget_terminal_focus_entry_tab_held) return false;
2326
+ if (input_event.kind == .key_up) {
2327
+ self.views[index].canvas_widget_terminal_focus_entry_tab_held = false;
2328
+ }
2329
+ return true;
2330
+ }
2331
+
2332
+ /// Consume the physical V release paired with a terminal Paste
2333
+ /// shortcut. Modifier flags describe the release instant, not
2334
+ /// the original key-down: Command/Ctrl may already be up, so the
2335
+ /// key-down classification is latched on the view instead of
2336
+ /// reconstructed here. A fresh V down retires a stale latch
2337
+ /// first (native menu Paste synthesizes a down with no release);
2338
+ /// the clipboard pass later in this input cycle re-arms it when
2339
+ /// that fresh down is another terminal Paste.
2340
+ pub fn consumeCanvasWidgetTerminalPasteKeyLifetime(self: *Runtime, input_event: GpuSurfaceInputEvent) bool {
2341
+ if (input_event.kind != .key_down and input_event.kind != .key_up) return false;
2342
+ if (!std.ascii.eqlIgnoreCase(input_event.key, "v")) return false;
2343
+ const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
2344
+ if (self.views[index].kind != .gpu_surface) return false;
2345
+ if (!self.views[index].canvas_widget_terminal_paste_v_held) return false;
2346
+ self.views[index].canvas_widget_terminal_paste_v_held = false;
2347
+ return input_event.kind == .key_up;
2348
+ }
2349
+
2165
2350
  /// Returns true when the key moved keyboard focus to a DIFFERENT
2166
2351
  /// widget — the caller stamps it onto the routed keyboard event
2167
2352
  /// (`focus_moved`) so tree rows can tell selection-follows-focus
@@ -2172,17 +2357,40 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2172
2357
  if (self.views[index].kind != .gpu_surface) return false;
2173
2358
 
2174
2359
  const current_id: ?canvas.ObjectId = if (self.views[index].canvas_widget_focused_id == 0) null else self.views[index].canvas_widget_focused_id;
2360
+ const layout = self.views[index].widgetLayoutTree();
2175
2361
  if (std.ascii.eqlIgnoreCase(input_event.key, "tab")) {
2362
+ // A terminal owns Tab as INPUT (completion, indentation,
2363
+ // and TUI navigation), not as focus traversal. Decide
2364
+ // against the pre-key focus before choosing the next
2365
+ // target: the routed keyboard pass below will therefore
2366
+ // address this same terminal and its emulator can encode
2367
+ // Tab/Shift+Tab for the pty. Disabled/hidden terminals
2368
+ // cannot occupy the focus register because
2369
+ // focusTargetById rejects them, so stale focus still
2370
+ // falls through to the ordinary traversal repair.
2371
+ if (current_id) |id| {
2372
+ if (layout.focusTargetById(id)) |current| {
2373
+ if (canvasWidgetTerminalOwnsTabInput(layout, current)) return false;
2374
+ }
2375
+ }
2176
2376
  const direction: canvas.WidgetFocusDirection = if (input_event.modifiers.shift) .backward else .forward;
2177
2377
  const target = if (current_id) |id|
2178
- self.views[index].canvasWidgetScopedFocusTarget(id, direction) orelse self.views[index].widgetLayoutTree().focusTarget(current_id, direction) orelse return false
2378
+ self.views[index].canvasWidgetScopedFocusTarget(id, direction) orelse layout.focusTarget(current_id, direction) orelse return false
2179
2379
  else
2180
- self.views[index].widgetLayoutTree().focusTarget(current_id, direction) orelse return false;
2181
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2380
+ layout.focusTarget(current_id, direction) orelse return false;
2381
+ const moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2382
+ if (moved and canvasWidgetTerminalOwnsTabInput(layout, target)) {
2383
+ // The key-down moved focus INTO this live terminal;
2384
+ // it is traversal, not terminal input. Hold that
2385
+ // classification through auto-repeat and key-up so
2386
+ // the same physical gesture cannot leak a Tab press
2387
+ // (legacy) or orphan release (kitty) into the pty.
2388
+ self.views[index].canvas_widget_terminal_focus_entry_tab_held = true;
2389
+ }
2390
+ return moved;
2182
2391
  }
2183
2392
 
2184
2393
  const focused_id = current_id orelse return false;
2185
- const layout = self.views[index].widgetLayoutTree();
2186
2394
  const focused = layout.focusTargetById(focused_id) orelse return false;
2187
2395
  // FRAMEWORK BEHAVIOR CHANGE (deliberate, scoped — the same
2188
2396
  // seam as the keyboard-routing gate below): arrows and
@@ -2315,6 +2523,14 @@ fn runtimeFindViewIndex(self: anytype, window_id: platform.WindowId, label: []co
2315
2523
  return null;
2316
2524
  }
2317
2525
 
2526
+ fn canvasWidgetTerminalOwnsTabInput(layout: canvas.WidgetLayoutTree, target: canvas.WidgetFocusTarget) bool {
2527
+ if (target.kind != .terminal or target.index >= layout.nodes.len) return false;
2528
+ const terminal = layout.nodes[target.index].widget.terminal;
2529
+ if (terminal.pty == 0) return false;
2530
+ const grid = terminal.grid orelse return false;
2531
+ return grid.running;
2532
+ }
2533
+
2318
2534
  fn canvasDirtyRegionForView(view_frame: geometry.RectF, local_dirty: geometry.RectF) ?geometry.RectF {
2319
2535
  const normalized_view = view_frame.normalized();
2320
2536
  const surface_bounds = geometry.RectF.init(0, 0, normalized_view.width, normalized_view.height);