@native-sdk/cli 0.5.1 → 0.5.2

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 (44) hide show
  1. package/package.json +9 -9
  2. package/packages/core/package-lock.json +2 -2
  3. package/packages/core/package.json +1 -1
  4. package/skill-data/native-ui/SKILL.md +2 -2
  5. package/src/platform/types.zig +9 -0
  6. package/src/primitives/canvas/root.zig +1 -0
  7. package/src/primitives/canvas/tokens.zig +170 -7
  8. package/src/primitives/canvas/ui.zig +27 -5
  9. package/src/primitives/canvas/ui_markup.zig +27 -4
  10. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  11. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  12. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  13. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  14. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  15. package/src/primitives/canvas/ui_schema.zig +15 -1
  16. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  17. package/src/primitives/canvas/widget_builtin_tests.zig +130 -0
  18. package/src/primitives/canvas/widget_layout.zig +4 -1
  19. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  20. package/src/primitives/canvas/widget_tree.zig +14 -2
  21. package/src/primitives/canvas/widgets.zig +12 -0
  22. package/src/runtime/automation_widget_dispatch.zig +95 -28
  23. package/src/runtime/canvas_frame.zig +15 -0
  24. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  25. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  26. package/src/runtime/canvas_widget_events.zig +1271 -3
  27. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  28. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  29. package/src/runtime/canvas_widget_state.zig +82 -5
  30. package/src/runtime/core.zig +14 -0
  31. package/src/runtime/flow.zig +24 -1
  32. package/src/runtime/gpu_surface_events.zig +44 -5
  33. package/src/runtime/session_journal.zig +25 -13
  34. package/src/runtime/session_record.zig +166 -0
  35. package/src/runtime/session_tests.zig +453 -0
  36. package/src/runtime/ui_app.zig +6 -1
  37. package/src/runtime/ui_app_tests.zig +460 -0
  38. package/src/runtime/view.zig +86 -0
  39. package/src/runtime/view_widget_text.zig +18 -1
  40. package/src/runtime/view_widget_tree.zig +339 -20
  41. package/src/runtime/widget_bridge.zig +26 -0
  42. package/src/runtime/window_storage.zig +61 -15
  43. package/src/runtime/window_view_runtime.zig +13 -0
  44. package/src/runtime/window_views.zig +6 -0
@@ -16,7 +16,6 @@ const AutomationProvenanceTarget = automation_commands.AutomationProvenanceTarge
16
16
  const AutomationWidgetWheel = automation_commands.AutomationWidgetWheel;
17
17
  const AutomationWidgetKey = automation_commands.AutomationWidgetKey;
18
18
  const AutomationWidgetPointerDrag = automation_commands.AutomationWidgetPointerDrag;
19
- const automationWidgetActionSupported = automation_commands.automationWidgetActionSupported;
20
19
  const parseAutomationTextSelection = automation_commands.parseAutomationTextSelection;
21
20
  const parseAutomationDragDelta = automation_commands.parseAutomationDragDelta;
22
21
  const parseAutomationDropPaths = automation_commands.parseAutomationDropPaths;
@@ -27,24 +26,40 @@ const validateViewLabel = validation.validateViewLabel;
27
26
 
28
27
  pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
29
28
  return struct {
29
+ /// The automation `widget_action` command surface delegates to
30
+ /// the accessibility dispatch rather than switching over the
31
+ /// verbs itself: one choke point performs the verb AND stages
32
+ /// the outer-wins `widget_accessibility_action` journal record,
33
+ /// so a recorded session replays the verb — focus included —
34
+ /// instead of replaying its untargeted synthesized children
35
+ /// against whatever focus the session happened to hold.
30
36
  pub fn dispatchAutomationWidgetAction(self: *Runtime, app: runtime_api.App(Runtime), action: AutomationWidgetAction) anyerror!void {
31
- const view_index = try automationWidgetActionViewIndex(self, action);
32
- switch (action.action) {
33
- .focus => try focusAutomationCanvasWidget(self, view_index, action.id),
34
- .press => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "enter"),
35
- .toggle => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "space"),
36
- .increment => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .increment)),
37
- .decrement => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .decrement)),
38
- .set_text => try setAutomationCanvasWidgetText(self, app, view_index, action.id, action.value),
39
- .set_selection => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_selection = try parseAutomationTextSelection(action.value) }),
40
- .set_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_composition = .{ .text = action.value } }),
41
- .commit_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .commit_composition),
42
- .cancel_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .cancel_composition),
43
- .select => try selectAutomationCanvasWidget(self, view_index, action.id),
44
- .drag => try dispatchAutomationCanvasWidgetDrag(self, app, view_index, action.id, action.value),
45
- .drop_files => try dispatchAutomationCanvasWidgetFileDrop(self, app, view_index, action.id, action.value),
46
- .dismiss => try dismissAutomationCanvasWidget(self, app, view_index, action.id),
47
- }
37
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
38
+ _ = try self.dispatchCanvasWidgetAccessibilityAction(app, self.views[view_index].window_id, self.views[view_index].label, .{
39
+ .id = action.id,
40
+ .action = canvasWidgetActionKindFromAutomation(action.action),
41
+ .text = action.value,
42
+ .selection = if (action.action == .set_selection) try parseAutomationTextSelection(action.value) else null,
43
+ });
44
+ }
45
+
46
+ fn canvasWidgetActionKindFromAutomation(kind: automation_commands.AutomationWidgetActionKind) runtime_api.CanvasWidgetAccessibilityActionKind {
47
+ return switch (kind) {
48
+ .focus => .focus,
49
+ .press => .press,
50
+ .toggle => .toggle,
51
+ .increment => .increment,
52
+ .decrement => .decrement,
53
+ .set_text => .set_text,
54
+ .set_selection => .set_selection,
55
+ .set_composition => .set_composition,
56
+ .commit_composition => .commit_composition,
57
+ .cancel_composition => .cancel_composition,
58
+ .select => .select,
59
+ .drag => .drag,
60
+ .drop_files => .drop_files,
61
+ .dismiss => .dismiss,
62
+ };
48
63
  }
49
64
 
50
65
  pub fn dispatchAutomationWidgetClick(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
@@ -349,6 +364,17 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
349
364
  const previous_state = self.views[view_index].canvasWidgetRenderState();
350
365
  self.views[view_index].canvas_widget_focused_id = target.id;
351
366
  self.views[view_index].canvas_widget_focus_visible_id = focus_visible_id;
367
+ // Pointer-contract provenance: a programmatic ring
368
+ // (editables only) never carries the keyboard's
369
+ // standing reveal intent into a layout adoption.
370
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
371
+ // The pointer contract extends to tooltips: this move
372
+ // hides a focus-owned tooltip and reveals nothing (see
373
+ // updateCanvasTooltipIntentForProgrammaticFocusMove).
374
+ // Inside the changed-guard on purpose — re-focusing the
375
+ // widget whose focus-shown tooltip is up with the ring
376
+ // intact is not a move, and leaves it alone.
377
+ try CanvasWidgetEventMethods().updateCanvasTooltipIntentForProgrammaticFocusMove(self, view_index);
352
378
  // A focus change repaints; record the automation input so
353
379
  // the completing frame publishes (same contract as select
354
380
  // and text edits). Callers that dispatch a follow-up input
@@ -367,12 +393,18 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
367
393
  // the way a Tab-then-key would: escalate exactly this target
368
394
  // kind to the ring register before dispatching. Every other
369
395
  // kind keeps the quiet programmatic focus it always had.
396
+ // The escalation deliberately skips the tooltip machine —
397
+ // it is still programmatic focus (no reveal), and the focus
398
+ // MOVE above already hid any focus-owned tooltip.
370
399
  if (self.views[view_index].canvasWidgetNodeIndexById(id)) |node_index| {
371
400
  const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
372
401
  const plain_list_row = widget.kind == .list_item and widget.semantics.role != .treeitem;
373
402
  if (plain_list_row and self.views[view_index].canvas_widget_focus_visible_id != id) {
374
403
  const previous_state = self.views[view_index].canvasWidgetRenderState();
375
404
  self.views[view_index].canvas_widget_focus_visible_id = id;
405
+ // Still programmatic (no reveal — see the comment
406
+ // above), so no keyboard provenance either.
407
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
376
408
  try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
377
409
  }
378
410
  }
@@ -450,15 +482,57 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
450
482
  } });
451
483
  }
452
484
 
453
- pub fn editAutomationCanvasWidgetText(self: *Runtime, view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
485
+ /// Composition edits ride the SAME ime input events a real IME
486
+ /// session produces (`setAutomationCanvasWidgetText`'s
487
+ /// philosophy): the dispatch applies the edit to the retained
488
+ /// editor, stamps it onto the routed keyboard event so the app's
489
+ /// `on_input` mirror hears it, and journals the input so a
490
+ /// recorded session replays the composition byte-identically.
491
+ /// Writing the editor directly (the previous shape) kept the
492
+ /// model out of the loop — the same divergence the keyboard
493
+ /// choke point closes for Escape's clear.
494
+ pub fn composeAutomationCanvasWidgetText(
495
+ self: *Runtime,
496
+ app: runtime_api.App(Runtime),
497
+ view_index: usize,
498
+ id: canvas.ObjectId,
499
+ kind: platform.GpuSurfaceInputKind,
500
+ text: []const u8,
501
+ ) anyerror!void {
454
502
  try focusAutomationCanvasWidget(self, view_index, id);
455
503
  if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
456
- const dirty = try self.views[view_index].applyCanvasWidgetTextEdit(id, edit) orelse return;
504
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
505
+ .window_id = self.views[view_index].window_id,
506
+ .label = self.views[view_index].label,
507
+ .kind = kind,
508
+ .timestamp_ns = automationInputTimestampNs(),
509
+ .text = text,
510
+ } });
511
+ }
512
+
513
+ /// Selection edits have no platform input kind to ride, so the
514
+ /// verb synthesizes the routed keyboard event the clipboard and
515
+ /// context-menu edits use: the keyboard choke point applies the
516
+ /// stamped edit to the retained editor and the app dispatch
517
+ /// keeps the model's selection mirror honest. (The journal sees
518
+ /// this verb as the outer `widget_accessibility_action` record
519
+ /// its dispatch stages; replaying that record re-runs the verb.)
520
+ pub fn editAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
521
+ try focusAutomationCanvasWidget(self, view_index, id);
522
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
523
+ const target = self.views[view_index].widgetLayoutTree().focusTargetById(id) orelse return error.InvalidCommand;
524
+ var keyboard_event: runtime_api.CanvasWidgetKeyboardEvent = .{
525
+ .window_id = self.views[view_index].window_id,
526
+ .view_label = self.views[view_index].label,
527
+ .keyboard = .{ .phase = .key_down, .focused_id = id, .edit = edit },
528
+ .target = target,
529
+ };
457
530
  // Same observability contract as selectAutomationCanvasWidget:
458
531
  // the repaint this edit triggers must publish its completing
459
532
  // frame, so record the automation input it resolves.
460
533
  self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
461
- try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
534
+ try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &keyboard_event);
535
+ try self.dispatchEvent(app, .{ .canvas_widget_keyboard = keyboard_event });
462
536
  }
463
537
 
464
538
  pub fn dispatchAutomationCanvasWidgetDrag(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
@@ -520,13 +594,6 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
520
594
  } });
521
595
  }
522
596
 
523
- fn automationWidgetActionViewIndex(self: *Runtime, action: AutomationWidgetAction) anyerror!usize {
524
- const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
525
- const actions = canvasWidgetActionsForId(self, view_index, action.id) orelse return error.InvalidCommand;
526
- if (!automationWidgetActionSupported(actions, action.action)) return error.InvalidCommand;
527
- return view_index;
528
- }
529
-
530
597
  fn automationWidgetTargetViewIndex(self: *Runtime, target: AutomationWidgetTarget) anyerror!usize {
531
598
  return automationGpuSurfaceViewIndexByLabel(self, target.view_label);
532
599
  }
@@ -1134,6 +1134,21 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1134
1134
  if (self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns)) {
1135
1135
  self.invalidateFor(.state, self.views[index].frame);
1136
1136
  }
1137
+ // An armed tooltip show delay — and a running anchor-gap
1138
+ // transit grace — only fire on a presented frame's
1139
+ // timestamp, so frames must keep coming while either is
1140
+ // pending: the render-animation pump's policy. This
1141
+ // per-frame leg takes over from the FIRST invalidation,
1142
+ // which the intent choke point kicks the moment any
1143
+ // deadline arms (reconcileCanvasTooltipIntent step 5 —
1144
+ // a deadline armed by an event that repainted nothing
1145
+ // would otherwise wait forever for a frame nothing
1146
+ // requested). Settled shown tooltips and the warm
1147
+ // window need no pump: both step on journaled input
1148
+ // timestamps.
1149
+ if (self.views[index].canvasTooltipIntentArmed()) {
1150
+ self.invalidateFor(.state, self.views[index].frame);
1151
+ }
1137
1152
  } else {
1138
1153
  self.views[index].recordCanvasFrame(canvas_frame);
1139
1154
  }
@@ -132,80 +132,89 @@ fn pickerOptions() PickerApp.Options {
132
132
  };
133
133
  }
134
134
 
135
- const Fixture = struct {
136
- harness: *core.TestHarness(),
137
- app_state: *PickerApp,
138
- app: core.App,
139
-
140
- fn create() !Fixture {
141
- const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
142
- errdefer harness.destroy(std.testing.allocator);
143
- harness.null_platform.gpu_surfaces = true;
144
- const app_state = try PickerApp.create(std.heap.page_allocator, pickerOptions());
145
- const app = app_state.app();
146
- try harness.start(app);
147
- try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
148
- .label = canvas_label,
149
- .size = geometry.SizeF.init(400, 300),
150
- .scale_factor = 2,
151
- .frame_index = 1,
152
- .timestamp_ns = 1_000_000,
153
- .nonblank = true,
154
- } });
155
- return .{ .harness = harness, .app_state = app_state, .app = app };
156
- }
135
+ /// The TEA harness shape every anchored fixture in this file shares,
136
+ /// parameterized over the app so the tooltip-coexistence picker below
137
+ /// reuses the picker's dispatch helpers verbatim.
138
+ fn AppFixture(comptime AppType: type, comptime appOptions: fn () AppType.Options) type {
139
+ return struct {
140
+ harness: *core.TestHarness(),
141
+ app_state: *AppType,
142
+ app: core.App,
143
+
144
+ const Self = @This();
145
+
146
+ fn create() !Self {
147
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
148
+ errdefer harness.destroy(std.testing.allocator);
149
+ harness.null_platform.gpu_surfaces = true;
150
+ const app_state = try AppType.create(std.heap.page_allocator, appOptions());
151
+ const app = app_state.app();
152
+ try harness.start(app);
153
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
154
+ .label = canvas_label,
155
+ .size = geometry.SizeF.init(400, 300),
156
+ .scale_factor = 2,
157
+ .frame_index = 1,
158
+ .timestamp_ns = 1_000_000,
159
+ .nonblank = true,
160
+ } });
161
+ return .{ .harness = harness, .app_state = app_state, .app = app };
162
+ }
157
163
 
158
- fn destroy(self: Fixture) void {
159
- self.app_state.destroy();
160
- self.harness.destroy(std.testing.allocator);
161
- }
164
+ fn destroy(self: Self) void {
165
+ self.app_state.destroy();
166
+ self.harness.destroy(std.testing.allocator);
167
+ }
162
168
 
163
- fn widgetIdByText(self: Fixture, kind: canvas.WidgetKind, text: []const u8) ?canvas.ObjectId {
164
- return findIn(self.app_state.tree.?.root, kind, text);
165
- }
169
+ fn widgetIdByText(self: Self, kind: canvas.WidgetKind, text: []const u8) ?canvas.ObjectId {
170
+ return findIn(self.app_state.tree.?.root, kind, text);
171
+ }
166
172
 
167
- fn findIn(widget: canvas.Widget, kind: canvas.WidgetKind, text: []const u8) ?canvas.ObjectId {
168
- if (widget.kind == kind and std.mem.eql(u8, widget.text, text)) return widget.id;
169
- for (widget.children) |child| {
170
- if (findIn(child, kind, text)) |id| return id;
173
+ fn findIn(widget: canvas.Widget, kind: canvas.WidgetKind, text: []const u8) ?canvas.ObjectId {
174
+ if (widget.kind == kind and std.mem.eql(u8, widget.text, text)) return widget.id;
175
+ for (widget.children) |child| {
176
+ if (findIn(child, kind, text)) |id| return id;
177
+ }
178
+ return null;
171
179
  }
172
- return null;
173
- }
174
180
 
175
- fn retainedFrame(self: Fixture, id: canvas.ObjectId) !?geometry.RectF {
176
- const layout = try self.harness.runtime.canvasWidgetLayout(1, canvas_label);
177
- const node = layout.findById(id) orelse return null;
178
- if (node.widget.semantics.hidden) return null;
179
- return node.frame;
180
- }
181
+ fn retainedFrame(self: Self, id: canvas.ObjectId) !?geometry.RectF {
182
+ const layout = try self.harness.runtime.canvasWidgetLayout(1, canvas_label);
183
+ const node = layout.findById(id) orelse return null;
184
+ if (node.widget.semantics.hidden) return null;
185
+ return node.frame;
186
+ }
181
187
 
182
- fn pointer(self: Fixture, kind: support.platform.GpuSurfaceInputKind, point: geometry.PointF) !void {
183
- try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
184
- .label = canvas_label,
185
- .kind = kind,
186
- .x = point.x,
187
- .y = point.y,
188
- } });
189
- }
188
+ fn pointer(self: Self, kind: support.platform.GpuSurfaceInputKind, point: geometry.PointF) !void {
189
+ try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
190
+ .label = canvas_label,
191
+ .kind = kind,
192
+ .x = point.x,
193
+ .y = point.y,
194
+ } });
195
+ }
190
196
 
191
- fn click(self: Fixture, point: geometry.PointF) !void {
192
- try self.pointer(.pointer_down, point);
193
- try self.pointer(.pointer_up, point);
194
- }
197
+ fn click(self: Self, point: geometry.PointF) !void {
198
+ try self.pointer(.pointer_down, point);
199
+ try self.pointer(.pointer_up, point);
200
+ }
195
201
 
196
- fn clickWidget(self: Fixture, id: canvas.ObjectId) !void {
197
- const frame = (try self.retainedFrame(id)) orelse return error.TestUnexpectedResult;
198
- try self.click(frame.center());
199
- }
202
+ fn clickWidget(self: Self, id: canvas.ObjectId) !void {
203
+ const frame = (try self.retainedFrame(id)) orelse return error.TestUnexpectedResult;
204
+ try self.click(frame.center());
205
+ }
200
206
 
201
- fn key(self: Fixture, name: []const u8) !void {
202
- try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
203
- .label = canvas_label,
204
- .kind = .key_down,
205
- .key = name,
206
- } });
207
- }
208
- };
207
+ fn key(self: Self, name: []const u8) !void {
208
+ try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
209
+ .label = canvas_label,
210
+ .kind = .key_down,
211
+ .key = name,
212
+ } });
213
+ }
214
+ };
215
+ }
216
+
217
+ const Fixture = AppFixture(PickerApp, pickerOptions);
209
218
 
210
219
  test "anchored picker: trigger opens, menu floats, item click picks and closes" {
211
220
  const fixture = try Fixture.create();
@@ -676,3 +685,182 @@ test "the per-view anchored budget rejects a surface per row loudly" {
676
685
  harness.runtime.setCanvasWidgetLayout(1, "canvas", over_budget),
677
686
  );
678
687
  }
688
+
689
+ // ------------------------------------------- tooltip + menu coexistence
690
+ //
691
+ // With `<tooltip>` anchorable beside `dropdown-menu`, one trigger stack
692
+ // can float TWO anchored surfaces at once: Tab earns the focus-shown
693
+ // tooltip, ArrowDown opens the menu beneath it. The tests below pin the
694
+ // keymap against that coexistence — the menu-specific lookups must scan
695
+ // FOR menu kinds instead of kind-checking whatever floats topmost, and
696
+ // Escape peels one surface per press, topmost (the tooltip) first.
697
+
698
+ const CoexistModel = struct {
699
+ open: bool = false,
700
+ picked: u32 = 99,
701
+ picks: u32 = 0,
702
+ toggles: u32 = 0,
703
+ dismissals: u32 = 0,
704
+ };
705
+
706
+ const CoexistMsg = union(enum) {
707
+ toggle_picker,
708
+ close_picker,
709
+ pick: u32,
710
+ noop,
711
+ };
712
+
713
+ const CoexistApp = ui_app_model.UiApp(CoexistModel, CoexistMsg);
714
+
715
+ fn coexistUpdate(model: *CoexistModel, msg: CoexistMsg) void {
716
+ switch (msg) {
717
+ .toggle_picker => {
718
+ model.open = !model.open;
719
+ model.toggles += 1;
720
+ },
721
+ .close_picker => {
722
+ model.open = false;
723
+ model.dismissals += 1;
724
+ },
725
+ .pick => |index| {
726
+ model.picked = index;
727
+ model.picks += 1;
728
+ model.open = false;
729
+ },
730
+ .noop => {},
731
+ }
732
+ }
733
+
734
+ /// The coexistence stack in the order that shadows: select trigger,
735
+ /// then the anchored dropdown-menu, then the anchored tooltip LAST —
736
+ /// while focus-shown, the tooltip is the topmost anchored child of the
737
+ /// very stack that anchors the open menu. The tooltip carries an
738
+ /// explicit key so its identity survives the open/close rebuilds that
739
+ /// insert and remove the menu ahead of it.
740
+ fn coexistView(ui: *CoexistApp.Ui, model: *const CoexistModel) CoexistApp.Ui.Node {
741
+ const trigger = ui.el(.select, .{ .text = "Repo", .width = 160, .on_press = .toggle_picker }, .{});
742
+ const tooltip = ui.el(.tooltip, .{ .key = .{ .int = 7 }, .text = "Choose the repository", .anchor = .above }, .{});
743
+ const picker = if (model.open) ui.stack(.{ .height = 28 }, .{
744
+ trigger,
745
+ ui.el(.dropdown_menu, .{
746
+ .key = .{ .int = 3 },
747
+ .anchor = .below,
748
+ .anchor_alignment = .stretch,
749
+ .width = 160,
750
+ .height = 90,
751
+ .on_dismiss = .close_picker,
752
+ }, .{
753
+ ui.el(.menu_item, .{ .key = .{ .int = 0 }, .text = "Alpha", .height = 26, .selected = model.picked == 0, .on_press = CoexistMsg{ .pick = 0 } }, .{}),
754
+ ui.el(.menu_item, .{ .key = .{ .int = 1 }, .text = "Beta", .height = 26, .selected = model.picked == 1, .on_press = CoexistMsg{ .pick = 1 } }, .{}),
755
+ }),
756
+ tooltip,
757
+ }) else ui.stack(.{ .height = 28 }, .{ trigger, tooltip });
758
+
759
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
760
+ picker,
761
+ ui.button(.{ .on_press = .noop }, "After"),
762
+ });
763
+ }
764
+
765
+ fn coexistOptions() CoexistApp.Options {
766
+ return .{
767
+ .name = "ui-app-coexist",
768
+ .scene = picker_scene,
769
+ .canvas_label = canvas_label,
770
+ .update = coexistUpdate,
771
+ .view = coexistView,
772
+ };
773
+ }
774
+
775
+ const CoexistFixture = AppFixture(CoexistApp, coexistOptions);
776
+
777
+ /// Tab onto the select earns the focus-shown tooltip, then ArrowDown
778
+ /// opens the menu beneath it. Returns the trigger id after asserting
779
+ /// the coexistence really holds: menu mounted AND tooltip shown.
780
+ fn coexistOpenWithTooltip(fixture: CoexistFixture) !canvas.ObjectId {
781
+ const trigger_id = fixture.widgetIdByText(.select, "Repo").?;
782
+ try fixture.key("tab");
783
+ try std.testing.expectEqual(trigger_id, fixture.harness.runtime.views[0].canvas_widget_focus_visible_id);
784
+ const tooltip_id = fixture.widgetIdByText(.tooltip, "Choose the repository").?;
785
+ try std.testing.expectEqual(tooltip_id, fixture.harness.runtime.views[0].canvas_tooltip_shown_id);
786
+
787
+ // ArrowDown on the closed trigger presses it (the model-owned
788
+ // open); the arrow is no activation key, so the focus-shown
789
+ // tooltip survives the press AND the rebuild that mounts the menu.
790
+ try fixture.key("arrowdown");
791
+ try std.testing.expect(fixture.app_state.model.open);
792
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.toggles);
793
+ try std.testing.expectEqual(trigger_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
794
+ try std.testing.expectEqual(tooltip_id, fixture.harness.runtime.views[0].canvas_tooltip_shown_id);
795
+ try std.testing.expect((try fixture.retainedFrame(tooltip_id)) != null);
796
+ try std.testing.expect((try fixture.retainedFrame(fixture.widgetIdByText(.menu_item, "Alpha").?)) != null);
797
+ return trigger_id;
798
+ }
799
+
800
+ test "tooltip coexistence: arrows walk into the open menu beneath the focus-shown tooltip" {
801
+ const fixture = try CoexistFixture.create();
802
+ defer fixture.destroy();
803
+
804
+ _ = try coexistOpenWithTooltip(fixture);
805
+
806
+ // The next ArrowDown walks INTO the menu — the tooltip floating
807
+ // topmost must not shadow the owned-menu lookup into re-pressing
808
+ // the trigger (which would toggle the picker closed).
809
+ const alpha_id = fixture.widgetIdByText(.menu_item, "Alpha").?;
810
+ try fixture.key("arrowdown");
811
+ try std.testing.expectEqual(alpha_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
812
+ try std.testing.expect(fixture.app_state.model.open);
813
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.toggles);
814
+
815
+ // Entering the menu moved focus off the trigger: the focus-shown
816
+ // tooltip hides through its own blur cause, not through any menu
817
+ // machinery.
818
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), fixture.harness.runtime.views[0].canvas_tooltip_shown_id);
819
+ }
820
+
821
+ test "tooltip coexistence: Tab departure closes the menu the tooltip floats over" {
822
+ const fixture = try CoexistFixture.create();
823
+ defer fixture.destroy();
824
+
825
+ const trigger_id = try coexistOpenWithTooltip(fixture);
826
+ const tooltip_id = fixture.harness.runtime.views[0].canvas_tooltip_shown_id;
827
+
828
+ // Tab is focus departure: it must find and dismiss the MENU even
829
+ // though the tooltip is the topmost anchored child, consume the
830
+ // Tab, and leave the keyboard on the trigger. The tooltip is not
831
+ // the departure's business: focus never left the trigger, so the
832
+ // focus-shown tooltip stays.
833
+ try fixture.key("tab");
834
+ try std.testing.expect(!fixture.app_state.model.open);
835
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.dismissals);
836
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.picks);
837
+ try std.testing.expectEqual(trigger_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
838
+ try std.testing.expectEqual(tooltip_id, fixture.harness.runtime.views[0].canvas_tooltip_shown_id);
839
+ }
840
+
841
+ test "tooltip coexistence: escape peels the tooltip first, then the menu, one per press" {
842
+ const fixture = try CoexistFixture.create();
843
+ defer fixture.destroy();
844
+
845
+ const trigger_id = try coexistOpenWithTooltip(fixture);
846
+ const tooltip_id = fixture.harness.runtime.views[0].canvas_tooltip_shown_id;
847
+
848
+ // Escape dismisses exactly one surface per press, topmost
849
+ // (last-mounted) first: the tooltip goes while the menu stays
850
+ // open and the keyboard stays on the trigger.
851
+ try fixture.key("escape");
852
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), fixture.harness.runtime.views[0].canvas_tooltip_shown_id);
853
+ try std.testing.expect((try fixture.retainedFrame(tooltip_id)) == null);
854
+ try std.testing.expect(fixture.app_state.model.open);
855
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.dismissals);
856
+ try std.testing.expectEqual(trigger_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
857
+
858
+ // The next Escape reaches the menu through the model's on_dismiss,
859
+ // still without committing, and the keyboard stays on the trigger.
860
+ try fixture.key("escape");
861
+ try std.testing.expect(!fixture.app_state.model.open);
862
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.dismissals);
863
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.picks);
864
+ try std.testing.expectEqual(@as(u32, 99), fixture.app_state.model.picked);
865
+ try std.testing.expectEqual(trigger_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
866
+ }
@@ -274,8 +274,9 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
274
274
  /// the event to the app — the same two motions keyboard-driven
275
275
  /// edits perform, so runtime widget and app model stay in sync.
276
276
  fn applyEditKeyboardEvent(self: *Runtime, app: runtime_api.App(Runtime), keyboard_event: runtime_api.CanvasWidgetKeyboardEvent) anyerror!void {
277
- try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, keyboard_event);
278
- try self.dispatchEvent(app, .{ .canvas_widget_keyboard = keyboard_event });
277
+ var event = keyboard_event;
278
+ try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &event);
279
+ try self.dispatchEvent(app, .{ .canvas_widget_keyboard = event });
279
280
  }
280
281
 
281
282
  fn editableSelectionText(self: *Runtime, view_index: usize, target_id: canvas.ObjectId) ?[]const u8 {