@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.
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/skill-data/native-ui/SKILL.md +2 -2
- package/src/platform/types.zig +9 -0
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +27 -5
- package/src/primitives/canvas/ui_markup.zig +27 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +47 -0
- package/src/primitives/canvas/ui_markup_view.zig +10 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
- package/src/primitives/canvas/ui_schema.zig +15 -1
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_builtin_tests.zig +130 -0
- package/src/primitives/canvas/widget_layout.zig +4 -1
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +12 -0
- package/src/runtime/automation_widget_dispatch.zig +95 -28
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_events.zig +1271 -3
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +82 -5
- package/src/runtime/core.zig +14 -0
- package/src/runtime/flow.zig +24 -1
- package/src/runtime/gpu_surface_events.zig +44 -5
- package/src/runtime/session_journal.zig +25 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +453 -0
- package/src/runtime/ui_app.zig +6 -1
- package/src/runtime/ui_app_tests.zig +460 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
|
@@ -1986,6 +1986,466 @@ test "automation set_text routes through the input path so the elm mirror stays
|
|
|
1986
1986
|
}
|
|
1987
1987
|
}
|
|
1988
1988
|
|
|
1989
|
+
// -------------------------------------------- edit-derivation choke point
|
|
1990
|
+
|
|
1991
|
+
const search_mirror_canvas_label = "search-mirror-canvas";
|
|
1992
|
+
|
|
1993
|
+
const SearchMirrorModel = struct {
|
|
1994
|
+
query: canvas.TextBuffer(64) = .{},
|
|
1995
|
+
edit_count: u32 = 0,
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1998
|
+
const SearchMirrorMsg = union(enum) {
|
|
1999
|
+
query_edit: canvas.TextInputEvent,
|
|
2000
|
+
};
|
|
2001
|
+
|
|
2002
|
+
const SearchMirrorApp = ui_app_model.UiApp(SearchMirrorModel, SearchMirrorMsg);
|
|
2003
|
+
|
|
2004
|
+
fn searchMirrorUpdate(model: *SearchMirrorModel, msg: SearchMirrorMsg) void {
|
|
2005
|
+
switch (msg) {
|
|
2006
|
+
.query_edit => |edit| {
|
|
2007
|
+
model.query.apply(edit);
|
|
2008
|
+
model.edit_count += 1;
|
|
2009
|
+
},
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
fn searchMirrorView(ui: *SearchMirrorApp.Ui, model: *const SearchMirrorModel) SearchMirrorApp.Ui.Node {
|
|
2014
|
+
return ui.column(.{ .gap = 8, .padding = 12 }, .{
|
|
2015
|
+
ui.el(.search_field, .{
|
|
2016
|
+
.text = model.query.text(),
|
|
2017
|
+
.placeholder = "Search",
|
|
2018
|
+
.on_input = SearchMirrorApp.Ui.inputMsg(.query_edit),
|
|
2019
|
+
}, .{}),
|
|
2020
|
+
ui.text(.{}, if (model.query.len == 0) "Unfiltered" else "Filtered"),
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
const search_mirror_views = [_]app_manifest.ShellView{
|
|
2025
|
+
.{ .label = search_mirror_canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
|
|
2026
|
+
};
|
|
2027
|
+
const search_mirror_windows = [_]app_manifest.ShellWindow{.{
|
|
2028
|
+
.label = "main",
|
|
2029
|
+
.title = "SearchMirror",
|
|
2030
|
+
.width = 400,
|
|
2031
|
+
.height = 300,
|
|
2032
|
+
.views = &search_mirror_views,
|
|
2033
|
+
}};
|
|
2034
|
+
const search_mirror_scene: app_manifest.ShellConfig = .{ .windows = &search_mirror_windows };
|
|
2035
|
+
|
|
2036
|
+
fn startSearchMirror(harness: *core.TestHarness(), app_state: *SearchMirrorApp) !void {
|
|
2037
|
+
app_state.* = SearchMirrorApp.init(std.heap.page_allocator, .{}, .{
|
|
2038
|
+
.name = "ui-app-search-mirror",
|
|
2039
|
+
.scene = search_mirror_scene,
|
|
2040
|
+
.canvas_label = search_mirror_canvas_label,
|
|
2041
|
+
.update = searchMirrorUpdate,
|
|
2042
|
+
.view = searchMirrorView,
|
|
2043
|
+
});
|
|
2044
|
+
const app = app_state.app();
|
|
2045
|
+
try harness.start(app);
|
|
2046
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
2047
|
+
.label = search_mirror_canvas_label,
|
|
2048
|
+
.size = geometry.SizeF.init(400, 300),
|
|
2049
|
+
.scale_factor = 1,
|
|
2050
|
+
.frame_index = 1,
|
|
2051
|
+
.timestamp_ns = 1_000_000,
|
|
2052
|
+
.nonblank = true,
|
|
2053
|
+
} });
|
|
2054
|
+
try std.testing.expect(app_state.installed);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
fn searchMirrorHasText(app_state: *const SearchMirrorApp, text: []const u8) bool {
|
|
2058
|
+
const tree = app_state.tree orelse return false;
|
|
2059
|
+
return widgetTreeHasText(tree.root, text);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
fn widgetTreeHasText(widget: canvas.Widget, text: []const u8) bool {
|
|
2063
|
+
if (widget.kind == .text and std.mem.eql(u8, widget.text, text)) return true;
|
|
2064
|
+
for (widget.children) |child| {
|
|
2065
|
+
if (widgetTreeHasText(child, text)) return true;
|
|
2066
|
+
}
|
|
2067
|
+
return false;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
test "Escape's search-field clear reaches the model through the edit-derivation seam" {
|
|
2071
|
+
// The post-launch live-GUI bug: Escape made the runtime editor clear
|
|
2072
|
+
// the field VISUALLY while the model's `on_input` mirror never heard
|
|
2073
|
+
// anything — the list stayed filtered against a query the screen no
|
|
2074
|
+
// longer showed, and the next keystroke dispatched against the stale
|
|
2075
|
+
// term. The keyboard derivation now stamps the edit it applies onto
|
|
2076
|
+
// the dispatched event, so every formerly runtime-only edit (the
|
|
2077
|
+
// Escape clear, the composition cancel, the single-line ArrowUp/Down
|
|
2078
|
+
// caret jumps) reaches the model exactly as applied.
|
|
2079
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2080
|
+
defer harness.destroy(std.testing.allocator);
|
|
2081
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2082
|
+
|
|
2083
|
+
const app_state = try std.testing.allocator.create(SearchMirrorApp);
|
|
2084
|
+
defer std.testing.allocator.destroy(app_state);
|
|
2085
|
+
try startSearchMirror(harness, app_state);
|
|
2086
|
+
defer app_state.deinit();
|
|
2087
|
+
const app = app_state.app();
|
|
2088
|
+
|
|
2089
|
+
const field_id = findWidgetIdByKind(app_state.tree.?.root, .search_field).?;
|
|
2090
|
+
const field_frame = (try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label)).findById(field_id).?.frame;
|
|
2091
|
+
|
|
2092
|
+
// Click into the (empty) field to focus it and type through the
|
|
2093
|
+
// platform text channel.
|
|
2094
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2095
|
+
.window_id = 1,
|
|
2096
|
+
.label = search_mirror_canvas_label,
|
|
2097
|
+
.kind = .pointer_down,
|
|
2098
|
+
.x = field_frame.x + field_frame.width * 0.5,
|
|
2099
|
+
.y = field_frame.y + field_frame.height * 0.5,
|
|
2100
|
+
} });
|
|
2101
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2102
|
+
.window_id = 1,
|
|
2103
|
+
.label = search_mirror_canvas_label,
|
|
2104
|
+
.kind = .text_input,
|
|
2105
|
+
.text = "glass",
|
|
2106
|
+
} });
|
|
2107
|
+
try std.testing.expectEqualStrings("glass", app_state.model.query.text());
|
|
2108
|
+
try std.testing.expect(searchMirrorHasText(app_state, "Filtered"));
|
|
2109
|
+
|
|
2110
|
+
// ArrowUp jumps the caret to the start in a single-line field — a
|
|
2111
|
+
// runtime-only derivation before the stamp; the model's selection
|
|
2112
|
+
// mirror must follow so its next splice lands where the editor's
|
|
2113
|
+
// does.
|
|
2114
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2115
|
+
.window_id = 1,
|
|
2116
|
+
.label = search_mirror_canvas_label,
|
|
2117
|
+
.kind = .key_down,
|
|
2118
|
+
.key = "arrowup",
|
|
2119
|
+
} });
|
|
2120
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.query.selection);
|
|
2121
|
+
|
|
2122
|
+
// THE pin: Escape clears the field AND the model hears it.
|
|
2123
|
+
const edits_before_escape = app_state.model.edit_count;
|
|
2124
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2125
|
+
.window_id = 1,
|
|
2126
|
+
.label = search_mirror_canvas_label,
|
|
2127
|
+
.kind = .key_down,
|
|
2128
|
+
.key = "escape",
|
|
2129
|
+
} });
|
|
2130
|
+
try std.testing.expect(app_state.model.edit_count > edits_before_escape);
|
|
2131
|
+
try std.testing.expectEqualStrings("", app_state.model.query.text());
|
|
2132
|
+
try std.testing.expect(searchMirrorHasText(app_state, "Unfiltered"));
|
|
2133
|
+
|
|
2134
|
+
// The visual state agrees with the model: the retained editor and
|
|
2135
|
+
// the automation snapshot both show the cleared field.
|
|
2136
|
+
const cleared_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
2137
|
+
try std.testing.expectEqualStrings("", cleared_layout.findById(field_id).?.widget.text);
|
|
2138
|
+
const snapshot = harness.runtime.automationSnapshot("SearchMirror");
|
|
2139
|
+
for (snapshot.widgets) |widget| {
|
|
2140
|
+
if (widget.id == field_id) try std.testing.expectEqualStrings("", widget.text_value);
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// Escape during composition cancels the composition FIRST — and the
|
|
2144
|
+
// model hears that too (the second formerly runtime-only arm).
|
|
2145
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2146
|
+
.window_id = 1,
|
|
2147
|
+
.label = search_mirror_canvas_label,
|
|
2148
|
+
.kind = .ime_set_composition,
|
|
2149
|
+
.text = "ne",
|
|
2150
|
+
} });
|
|
2151
|
+
try std.testing.expectEqualStrings("ne", app_state.model.query.text());
|
|
2152
|
+
try std.testing.expect(app_state.model.query.composition != null);
|
|
2153
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2154
|
+
.window_id = 1,
|
|
2155
|
+
.label = search_mirror_canvas_label,
|
|
2156
|
+
.kind = .key_down,
|
|
2157
|
+
.key = "escape",
|
|
2158
|
+
} });
|
|
2159
|
+
try std.testing.expectEqualStrings("", app_state.model.query.text());
|
|
2160
|
+
try std.testing.expect(app_state.model.query.composition == null);
|
|
2161
|
+
const canceled_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
2162
|
+
try std.testing.expectEqualStrings("", canceled_layout.findById(field_id).?.widget.text);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
test "automation composition and selection verbs keep the model mirror consistent" {
|
|
2166
|
+
// The automation/accessibility text verbs (`widget-action ...
|
|
2167
|
+
// set_composition/commit_composition/cancel_composition`) used to
|
|
2168
|
+
// write the runtime editor directly — on-screen composition the
|
|
2169
|
+
// model never heard, the `set_text` bug's composition twin. They
|
|
2170
|
+
// now ride the SAME ime input events a real IME session produces
|
|
2171
|
+
// (journaled, stamped, dispatched); `set_selection` synthesizes the
|
|
2172
|
+
// stamped keyboard event the clipboard edits use.
|
|
2173
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2174
|
+
defer harness.destroy(std.testing.allocator);
|
|
2175
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2176
|
+
|
|
2177
|
+
const app_state = try std.testing.allocator.create(SearchMirrorApp);
|
|
2178
|
+
defer std.testing.allocator.destroy(app_state);
|
|
2179
|
+
try startSearchMirror(harness, app_state);
|
|
2180
|
+
defer app_state.deinit();
|
|
2181
|
+
const app = app_state.app();
|
|
2182
|
+
|
|
2183
|
+
const field_id = findWidgetIdByKind(app_state.tree.?.root, .search_field).?;
|
|
2184
|
+
|
|
2185
|
+
// Compose marked text: the editor shows it AND the model hears it.
|
|
2186
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2187
|
+
.view_label = search_mirror_canvas_label,
|
|
2188
|
+
.id = field_id,
|
|
2189
|
+
.action = .set_composition,
|
|
2190
|
+
.value = "ing",
|
|
2191
|
+
});
|
|
2192
|
+
try std.testing.expectEqualStrings("ing", app_state.model.query.text());
|
|
2193
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextRange, canvas.TextRange.init(0, 3)), app_state.model.query.composition);
|
|
2194
|
+
const composing_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
2195
|
+
try std.testing.expectEqualStrings("ing", composing_layout.findById(field_id).?.widget.text);
|
|
2196
|
+
|
|
2197
|
+
// Commit: composition resolves to plain text in both.
|
|
2198
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2199
|
+
.view_label = search_mirror_canvas_label,
|
|
2200
|
+
.id = field_id,
|
|
2201
|
+
.action = .commit_composition,
|
|
2202
|
+
});
|
|
2203
|
+
try std.testing.expectEqualStrings("ing", app_state.model.query.text());
|
|
2204
|
+
try std.testing.expect(app_state.model.query.composition == null);
|
|
2205
|
+
|
|
2206
|
+
// Select a range: the model's selection mirror follows.
|
|
2207
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2208
|
+
.view_label = search_mirror_canvas_label,
|
|
2209
|
+
.id = field_id,
|
|
2210
|
+
.action = .set_selection,
|
|
2211
|
+
.value = "0 3",
|
|
2212
|
+
});
|
|
2213
|
+
try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 3 }, app_state.model.query.selection);
|
|
2214
|
+
|
|
2215
|
+
// Cancel a fresh composition: the marked run vanishes from both.
|
|
2216
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2217
|
+
.view_label = search_mirror_canvas_label,
|
|
2218
|
+
.id = field_id,
|
|
2219
|
+
.action = .set_composition,
|
|
2220
|
+
.value = "aro",
|
|
2221
|
+
});
|
|
2222
|
+
try std.testing.expectEqualStrings("aro", app_state.model.query.text());
|
|
2223
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2224
|
+
.view_label = search_mirror_canvas_label,
|
|
2225
|
+
.id = field_id,
|
|
2226
|
+
.action = .cancel_composition,
|
|
2227
|
+
});
|
|
2228
|
+
try std.testing.expectEqualStrings("", app_state.model.query.text());
|
|
2229
|
+
try std.testing.expect(app_state.model.query.composition == null);
|
|
2230
|
+
const canceled_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
|
|
2231
|
+
try std.testing.expectEqualStrings("", canceled_layout.findById(field_id).?.widget.text);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// --------------------------------- combobox open-arrow (mirror invariant)
|
|
2235
|
+
|
|
2236
|
+
const combo_mirror_canvas_label = "combo-mirror-canvas";
|
|
2237
|
+
|
|
2238
|
+
const ComboMirrorModel = struct {
|
|
2239
|
+
query: canvas.TextBuffer(64) = .{},
|
|
2240
|
+
note: canvas.TextBuffer(64) = .{},
|
|
2241
|
+
open: bool = false,
|
|
2242
|
+
opens: u32 = 0,
|
|
2243
|
+
query_edits: u32 = 0,
|
|
2244
|
+
};
|
|
2245
|
+
|
|
2246
|
+
const ComboMirrorMsg = union(enum) {
|
|
2247
|
+
open_picker,
|
|
2248
|
+
close_picker,
|
|
2249
|
+
query_edit: canvas.TextInputEvent,
|
|
2250
|
+
note_edit: canvas.TextInputEvent,
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2253
|
+
const ComboMirrorApp = ui_app_model.UiApp(ComboMirrorModel, ComboMirrorMsg);
|
|
2254
|
+
|
|
2255
|
+
fn comboMirrorUpdate(model: *ComboMirrorModel, msg: ComboMirrorMsg) void {
|
|
2256
|
+
switch (msg) {
|
|
2257
|
+
.open_picker => {
|
|
2258
|
+
model.open = true;
|
|
2259
|
+
model.opens += 1;
|
|
2260
|
+
},
|
|
2261
|
+
.close_picker => model.open = false,
|
|
2262
|
+
.query_edit => |edit| {
|
|
2263
|
+
model.query.apply(edit);
|
|
2264
|
+
model.query_edits += 1;
|
|
2265
|
+
},
|
|
2266
|
+
.note_edit => |edit| model.note.apply(edit),
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
fn comboMirrorView(ui: *ComboMirrorApp.Ui, model: *const ComboMirrorModel) ComboMirrorApp.Ui.Node {
|
|
2271
|
+
const trigger = ui.el(.combobox, .{
|
|
2272
|
+
.text = model.query.text(),
|
|
2273
|
+
.placeholder = "Filter",
|
|
2274
|
+
.width = 200,
|
|
2275
|
+
.expanded = model.open,
|
|
2276
|
+
.on_press = .open_picker,
|
|
2277
|
+
.on_input = ComboMirrorApp.Ui.inputMsg(.query_edit),
|
|
2278
|
+
}, .{});
|
|
2279
|
+
const picker = if (model.open) ui.stack(.{ .height = 28 }, .{
|
|
2280
|
+
trigger,
|
|
2281
|
+
ui.el(.dropdown_menu, .{
|
|
2282
|
+
.anchor = .below,
|
|
2283
|
+
.anchor_alignment = .stretch,
|
|
2284
|
+
.width = 200,
|
|
2285
|
+
.height = 60,
|
|
2286
|
+
.on_dismiss = .close_picker,
|
|
2287
|
+
}, .{
|
|
2288
|
+
ui.el(.menu_item, .{ .key = .{ .int = 0 }, .text = "glass bead", .height = 26, .on_press = .close_picker }, .{}),
|
|
2289
|
+
ui.el(.menu_item, .{ .key = .{ .int = 1 }, .text = "glass jar", .height = 26, .on_press = .close_picker }, .{}),
|
|
2290
|
+
}),
|
|
2291
|
+
}) else ui.stack(.{ .height = 28 }, .{trigger});
|
|
2292
|
+
return ui.column(.{ .gap = 8, .padding = 12 }, .{
|
|
2293
|
+
picker,
|
|
2294
|
+
ui.el(.text_field, .{
|
|
2295
|
+
.text = model.note.text(),
|
|
2296
|
+
.placeholder = "Note",
|
|
2297
|
+
.width = 200,
|
|
2298
|
+
.on_input = ComboMirrorApp.Ui.inputMsg(.note_edit),
|
|
2299
|
+
}, .{}),
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
const combo_mirror_views = [_]app_manifest.ShellView{
|
|
2304
|
+
.{ .label = combo_mirror_canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
|
|
2305
|
+
};
|
|
2306
|
+
const combo_mirror_windows = [_]app_manifest.ShellWindow{.{
|
|
2307
|
+
.label = "main",
|
|
2308
|
+
.title = "ComboMirror",
|
|
2309
|
+
.width = 400,
|
|
2310
|
+
.height = 300,
|
|
2311
|
+
.views = &combo_mirror_views,
|
|
2312
|
+
}};
|
|
2313
|
+
const combo_mirror_scene: app_manifest.ShellConfig = .{ .windows = &combo_mirror_windows };
|
|
2314
|
+
|
|
2315
|
+
fn comboMirrorKey(harness: *core.TestHarness(), app: core.App, key: []const u8) !void {
|
|
2316
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2317
|
+
.window_id = 1,
|
|
2318
|
+
.label = combo_mirror_canvas_label,
|
|
2319
|
+
.kind = .key_down,
|
|
2320
|
+
.key = key,
|
|
2321
|
+
} });
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
fn comboMirrorRetainedSelection(harness: *core.TestHarness(), id: canvas.ObjectId) !?canvas.TextSelection {
|
|
2325
|
+
const layout = try harness.runtime.canvasWidgetLayout(1, combo_mirror_canvas_label);
|
|
2326
|
+
return layout.findById(id).?.widget.text_selection;
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
test "a closed combobox's open arrows move neither the retained caret nor the model mirror" {
|
|
2330
|
+
// The split-brain escapee: a CLOSED combobox maps ArrowUp/Down to
|
|
2331
|
+
// BOTH its open press (`widgetKeyboardControlIntent`'s menu-open
|
|
2332
|
+
// keys) and — through the single-line caret derivation — a stamped
|
|
2333
|
+
// caret jump. The app dispatch resolves the press FIRST, so the
|
|
2334
|
+
// runtime editor moved its caret while the model's mirror heard
|
|
2335
|
+
// nothing, and the next insert landed at two different offsets.
|
|
2336
|
+
// Opening wins (the platform convention): the derivation yields no
|
|
2337
|
+
// edit, and BOTH sides agree the arrow moved no caret.
|
|
2338
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2339
|
+
defer harness.destroy(std.testing.allocator);
|
|
2340
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2341
|
+
|
|
2342
|
+
const app_state = try std.testing.allocator.create(ComboMirrorApp);
|
|
2343
|
+
defer std.testing.allocator.destroy(app_state);
|
|
2344
|
+
app_state.* = ComboMirrorApp.init(std.heap.page_allocator, .{}, .{
|
|
2345
|
+
.name = "ui-app-combo-mirror",
|
|
2346
|
+
.scene = combo_mirror_scene,
|
|
2347
|
+
.canvas_label = combo_mirror_canvas_label,
|
|
2348
|
+
.update = comboMirrorUpdate,
|
|
2349
|
+
.view = comboMirrorView,
|
|
2350
|
+
});
|
|
2351
|
+
defer app_state.deinit();
|
|
2352
|
+
const app = app_state.app();
|
|
2353
|
+
try harness.start(app);
|
|
2354
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
2355
|
+
.label = combo_mirror_canvas_label,
|
|
2356
|
+
.size = geometry.SizeF.init(400, 300),
|
|
2357
|
+
.scale_factor = 1,
|
|
2358
|
+
.frame_index = 1,
|
|
2359
|
+
.timestamp_ns = 1_000_000,
|
|
2360
|
+
.nonblank = true,
|
|
2361
|
+
} });
|
|
2362
|
+
try std.testing.expect(app_state.installed);
|
|
2363
|
+
|
|
2364
|
+
const combo_id = findWidgetIdByKind(app_state.tree.?.root, .combobox).?;
|
|
2365
|
+
|
|
2366
|
+
// Focus WITHOUT pressing (a click on a combobox IS its open press),
|
|
2367
|
+
// type, and walk the caret off the end so a divergence would show.
|
|
2368
|
+
try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
|
|
2369
|
+
.view_label = combo_mirror_canvas_label,
|
|
2370
|
+
.id = combo_id,
|
|
2371
|
+
.action = .focus,
|
|
2372
|
+
});
|
|
2373
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2374
|
+
.window_id = 1,
|
|
2375
|
+
.label = combo_mirror_canvas_label,
|
|
2376
|
+
.kind = .text_input,
|
|
2377
|
+
.text = "glass",
|
|
2378
|
+
} });
|
|
2379
|
+
try comboMirrorKey(harness, app, "arrowleft");
|
|
2380
|
+
try comboMirrorKey(harness, app, "arrowleft");
|
|
2381
|
+
try std.testing.expectEqualStrings("glass", app_state.model.query.text());
|
|
2382
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
2383
|
+
|
|
2384
|
+
// THE pin: ArrowDown on the closed trigger opens the picker and
|
|
2385
|
+
// both carets stay at 3 — no query edit is heard or applied.
|
|
2386
|
+
const edits_before_open = app_state.model.query_edits;
|
|
2387
|
+
try comboMirrorKey(harness, app, "arrowdown");
|
|
2388
|
+
try std.testing.expect(app_state.model.open);
|
|
2389
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.model.opens);
|
|
2390
|
+
try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
|
|
2391
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
2392
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
2393
|
+
|
|
2394
|
+
// The OPEN-picker truth, pinned as-is: the next arrow walks the
|
|
2395
|
+
// keyboard INTO the mounted menu (the focus step consumes it before
|
|
2396
|
+
// routing reaches the trigger), so it is no caret edit either.
|
|
2397
|
+
const first_item_id = findWidgetIdByText(app_state.tree.?, .menu_item, "glass bead").?;
|
|
2398
|
+
try comboMirrorKey(harness, app, "arrowdown");
|
|
2399
|
+
try std.testing.expectEqual(first_item_id, harness.runtime.views[0].canvas_widget_focused_id);
|
|
2400
|
+
try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
|
|
2401
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
2402
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
2403
|
+
|
|
2404
|
+
// Escape is consumed by the DISMISSAL pass while the menu floats:
|
|
2405
|
+
// the picker closes through `on_dismiss` and the combobox's
|
|
2406
|
+
// Escape-clear never runs — the query survives.
|
|
2407
|
+
try comboMirrorKey(harness, app, "escape");
|
|
2408
|
+
try std.testing.expect(!app_state.model.open);
|
|
2409
|
+
try std.testing.expectEqualStrings("glass", app_state.model.query.text());
|
|
2410
|
+
try std.testing.expectEqual(combo_id, harness.runtime.views[0].canvas_widget_focused_id);
|
|
2411
|
+
|
|
2412
|
+
// ArrowUp on the closed trigger is the same open key: opens, and
|
|
2413
|
+
// both carets stay put again.
|
|
2414
|
+
try comboMirrorKey(harness, app, "arrowup");
|
|
2415
|
+
try std.testing.expect(app_state.model.open);
|
|
2416
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.model.opens);
|
|
2417
|
+
try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
|
|
2418
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
|
|
2419
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
|
|
2420
|
+
try comboMirrorKey(harness, app, "escape");
|
|
2421
|
+
try std.testing.expect(!app_state.model.open);
|
|
2422
|
+
|
|
2423
|
+
// The suppression is combobox-only: a plain text field keeps the
|
|
2424
|
+
// single-line ArrowUp/Down caret jumps, and the model mirror hears
|
|
2425
|
+
// them through the stamped edit (the #129 seam, unregressed).
|
|
2426
|
+
const note_id = findWidgetIdByKind(app_state.tree.?.root, .text_field).?;
|
|
2427
|
+
const note_frame = (try harness.runtime.canvasWidgetLayout(1, combo_mirror_canvas_label)).findById(note_id).?.frame;
|
|
2428
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2429
|
+
.window_id = 1,
|
|
2430
|
+
.label = combo_mirror_canvas_label,
|
|
2431
|
+
.kind = .pointer_down,
|
|
2432
|
+
.x = note_frame.x + note_frame.width * 0.5,
|
|
2433
|
+
.y = note_frame.y + note_frame.height * 0.5,
|
|
2434
|
+
} });
|
|
2435
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2436
|
+
.window_id = 1,
|
|
2437
|
+
.label = combo_mirror_canvas_label,
|
|
2438
|
+
.kind = .text_input,
|
|
2439
|
+
.text = "abc",
|
|
2440
|
+
} });
|
|
2441
|
+
try comboMirrorKey(harness, app, "arrowup");
|
|
2442
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.note.selection);
|
|
2443
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(0)), try comboMirrorRetainedSelection(harness, note_id));
|
|
2444
|
+
try comboMirrorKey(harness, app, "arrowdown");
|
|
2445
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.note.selection);
|
|
2446
|
+
try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, note_id));
|
|
2447
|
+
}
|
|
2448
|
+
|
|
1989
2449
|
// ------------------------------------------------- autofocus (notes flow)
|
|
1990
2450
|
|
|
1991
2451
|
const autofocus_canvas_label = "autofocus-canvas"; // shell scene label below
|
package/src/runtime/view.zig
CHANGED
|
@@ -425,8 +425,85 @@ pub const RuntimeView = struct {
|
|
|
425
425
|
scroll_driver_count: usize = 0,
|
|
426
426
|
canvas_widget_focused_id: canvas.ObjectId = 0,
|
|
427
427
|
canvas_widget_focus_visible_id: canvas.ObjectId = 0,
|
|
428
|
+
/// True when `canvas_widget_focus_visible_id` was written by the
|
|
429
|
+
/// KEYBOARD focus contract (`setCanvasWidgetFocusFromKeyboard`) —
|
|
430
|
+
/// the one focus path that reveals tooltips. Every other
|
|
431
|
+
/// focus-visible writer stamps false: pointer focus on editables
|
|
432
|
+
/// (the caret contract), programmatic/automation focus, the
|
|
433
|
+
/// automation key escalation on plain list rows, and the rebuild
|
|
434
|
+
/// and dismissal focus-return seams — all of which deliberately
|
|
435
|
+
/// skip the reveal (Base UI's focus-visible guard against
|
|
436
|
+
/// click-focus opens, and the reveals-are-transition-edges rule).
|
|
437
|
+
/// The layout-adoption reconcile reads this to decide whether a
|
|
438
|
+
/// tooltip newly bound beneath the standing focus-visible owner
|
|
439
|
+
/// inherits the keyboard's immediate reveal or must wait for the
|
|
440
|
+
/// next real focus arrival.
|
|
441
|
+
canvas_widget_focus_visible_keyboard: bool = false,
|
|
428
442
|
canvas_widget_hovered_id: canvas.ObjectId = 0,
|
|
429
443
|
canvas_widget_pressed_id: canvas.ObjectId = 0,
|
|
444
|
+
/// Hover-intent state for ANCHORED tooltips — runtime-owned
|
|
445
|
+
/// presentation chrome; the model never hears hover. `armed` is
|
|
446
|
+
/// the tooltip whose trigger is hovered while its show delay runs;
|
|
447
|
+
/// `shown` is the tooltip currently painted; `warm_until` is the
|
|
448
|
+
/// shared warm window after a pointer-hovered tooltip hides on
|
|
449
|
+
/// pointer leave (reaching another
|
|
450
|
+
/// trigger before it passes shows that tooltip immediately, the
|
|
451
|
+
/// dense-toolbar polish). Every timestamp lives on the RECORDED
|
|
452
|
+
/// input/frame clock (`canvasRenderAnimationStartNsForView` at
|
|
453
|
+
/// pointer dispatch, `GpuSurfaceFrameEvent.timestamp_ns` at frame
|
|
454
|
+
/// advance — never a wall clock), so a recorded hover-dwell
|
|
455
|
+
/// session replays its tooltip show/hide frames byte-identically.
|
|
456
|
+
canvas_tooltip_armed_id: canvas.ObjectId = 0,
|
|
457
|
+
canvas_tooltip_deadline_ns: u64 = 0,
|
|
458
|
+
canvas_tooltip_shown_id: canvas.ObjectId = 0,
|
|
459
|
+
canvas_tooltip_warm_until_ns: u64 = 0,
|
|
460
|
+
/// The TRIGGER each intent slot was earned through (the hover
|
|
461
|
+
/// target that armed the delay / the widget whose hover or
|
|
462
|
+
/// focus-visible showed the tooltip). Ownership is a live claim,
|
|
463
|
+
/// not a memento: a rebuild that removes, rekeys, disables, or
|
|
464
|
+
/// re-parents the owner invalidates the slot in
|
|
465
|
+
/// `pruneCanvasTooltipIntent` — the tooltip node alone surviving
|
|
466
|
+
/// is not enough to keep explaining a control that no longer
|
|
467
|
+
/// exists.
|
|
468
|
+
canvas_tooltip_armed_owner_id: canvas.ObjectId = 0,
|
|
469
|
+
canvas_tooltip_shown_owner_id: canvas.ObjectId = 0,
|
|
470
|
+
/// The pointer's last position while it held the shown tooltip —
|
|
471
|
+
/// on the owning trigger (seeded at arm/show) or inside the shown
|
|
472
|
+
/// tooltip's own frame. It is the apex of the transit corridor
|
|
473
|
+
/// (`canvasTooltipTravelRegionContains`) a leave-move is judged
|
|
474
|
+
/// against, so the corridor always fans out from where the pointer
|
|
475
|
+
/// actually left. Meaningful only while a pointer-shown tooltip is
|
|
476
|
+
/// up; every value it is compared against comes from journaled
|
|
477
|
+
/// pointer events, so replay sees identical corridors.
|
|
478
|
+
canvas_tooltip_pointer_from: geometry.PointF = geometry.PointF.zero(),
|
|
479
|
+
/// Nonzero while the pointer has left both the trigger and the
|
|
480
|
+
/// shown tooltip's frame but is still inside the transit corridor
|
|
481
|
+
/// between them: the deadline (recorded clock) by which it must
|
|
482
|
+
/// arrive. Each in-corridor move re-arms it, so slow deliberate
|
|
483
|
+
/// transits stay open (WCAG 1.4.13 hoverable content) while a
|
|
484
|
+
/// pointer that parks in the gap resolves deterministically on the
|
|
485
|
+
/// frame clock. 0 means no transit is in flight.
|
|
486
|
+
canvas_tooltip_transit_deadline_ns: u64 = 0,
|
|
487
|
+
/// True when the shown tooltip was revealed by keyboard
|
|
488
|
+
/// focus-visible rather than pointer hover. Focus-shown tooltips
|
|
489
|
+
/// follow shadcn's Base UI-backed defaults: they open instantly on
|
|
490
|
+
/// focus-visible, hide on blur, ignore pointer hover leaving OTHER
|
|
491
|
+
/// triggers, and never open the pointer's warm window when they
|
|
492
|
+
/// hide (deliberate keyboard motion is not a pointer sweep).
|
|
493
|
+
canvas_tooltip_shown_from_focus: bool = false,
|
|
494
|
+
/// The pointer's last JOURNALED position over this view — every
|
|
495
|
+
/// phase that carries a trustworthy point (hover, move, down, up,
|
|
496
|
+
/// wheel) updates it; null before the first pointer event and after
|
|
497
|
+
/// a `.cancel` (the pointer-exit AppKit/GTK/Win32 hosts emit, and
|
|
498
|
+
/// gesture cancels). Point-blind scroll reconciliation (kinetic
|
|
499
|
+
/// steps, native drivers, keyboard scrolling) re-hit-tests this
|
|
500
|
+
/// position against the post-scroll tree — the pointer did not
|
|
501
|
+
/// move, so where it last stood is where it still is — and a null
|
|
502
|
+
/// here means those paths must CLOSE pointer tooltip intent rather
|
|
503
|
+
/// than guess (see
|
|
504
|
+
/// reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent).
|
|
505
|
+
/// Journaled input only, so replay sees identical positions.
|
|
506
|
+
canvas_last_pointer_position: ?geometry.PointF = null,
|
|
430
507
|
/// Pointer position while the hovered widget draws hover-detail
|
|
431
508
|
/// chrome (a `.chart` with hover details opted in); null everywhere
|
|
432
509
|
/// else. Feeds `WidgetRenderState.hover_point`, so the display list
|
|
@@ -612,6 +689,15 @@ pub const RuntimeView = struct {
|
|
|
612
689
|
pub const canvasWidgetDismissibleSurfaceIndexForTarget = CanvasWidgetTreeMethods.canvasWidgetDismissibleSurfaceIndexForTarget;
|
|
613
690
|
pub const canvasWidgetAnchoredDismissibleChildIndex = CanvasWidgetTreeMethods.canvasWidgetAnchoredDismissibleChildIndex;
|
|
614
691
|
pub const canvasWidgetOwnedMenuSurfaceIndex = CanvasWidgetTreeMethods.canvasWidgetOwnedMenuSurfaceIndex;
|
|
692
|
+
pub const canvasWidgetOwnedTooltipIndex = CanvasWidgetTreeMethods.canvasWidgetOwnedTooltipIndex;
|
|
693
|
+
pub const canvasWidgetOwnedTooltipIdForOwner = CanvasWidgetTreeMethods.canvasWidgetOwnedTooltipIdForOwner;
|
|
694
|
+
pub const applyCanvasTooltipVisibility = CanvasWidgetTreeMethods.applyCanvasTooltipVisibility;
|
|
695
|
+
pub const applyCanvasTooltipVisibilityToNodes = CanvasWidgetTreeMethods.applyCanvasTooltipVisibilityToNodes;
|
|
696
|
+
pub const applyCanvasTooltipVisibilityToNodesForShownId = CanvasWidgetTreeMethods.applyCanvasTooltipVisibilityToNodesForShownId;
|
|
697
|
+
pub const pruneCanvasTooltipIntent = CanvasWidgetTreeMethods.pruneCanvasTooltipIntent;
|
|
698
|
+
pub const pruneCanvasTooltipIntentForLayout = CanvasWidgetTreeMethods.pruneCanvasTooltipIntentForLayout;
|
|
699
|
+
pub const canvasTooltipShownIdSurvivingLayout = CanvasWidgetTreeMethods.canvasTooltipShownIdSurvivingLayout;
|
|
700
|
+
pub const canvasTooltipIntentArmed = CanvasWidgetTreeMethods.canvasTooltipIntentArmed;
|
|
615
701
|
pub const canvasWidgetMenuSurfaceEntryId = CanvasWidgetTreeMethods.canvasWidgetMenuSurfaceEntryId;
|
|
616
702
|
pub const canvasWidgetAnchorTriggerFocusId = CanvasWidgetTreeMethods.canvasWidgetAnchorTriggerFocusId;
|
|
617
703
|
pub const canvasWidgetTopmostAnchoredDismissibleIndex = CanvasWidgetTreeMethods.canvasWidgetTopmostAnchoredDismissibleIndex;
|
|
@@ -63,7 +63,24 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
63
63
|
return newline_edit;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// On a CLOSED combobox these same arrows are the trigger's
|
|
67
|
+
// OPEN keys (`widgetKeyboardControlIntent`'s menu-open
|
|
68
|
+
// mapping, which the app dispatch resolves BEFORE any
|
|
69
|
+
// stamped edit): platform convention is that opening wins
|
|
70
|
+
// and the caret does not move, so the derivation yields no
|
|
71
|
+
// edit and the retained editor agrees with the model's "no
|
|
72
|
+
// edit" verdict. The app-side fallback derivation for
|
|
73
|
+
// events that never crossed the runtime
|
|
74
|
+
// (`textEditEvent()`'s generic keymap) has no ArrowUp/Down
|
|
75
|
+
// arm at all, so both derivations stay in agreement. Once
|
|
76
|
+
// the picker is OPEN the focus step walks the arrows into
|
|
77
|
+
// the mounted menu before routing reaches the trigger; an
|
|
78
|
+
// arrow that still lands on an EXPANDED trigger (no
|
|
79
|
+
// focusable menu entry mounted) keeps the caret jump — the
|
|
80
|
+
// control resolver ignores it there, so both sides hear
|
|
81
|
+
// the same move.
|
|
82
|
+
const arrow_opens_combobox = widget.kind == .combobox and !(widget.state.expanded orelse false);
|
|
83
|
+
if (!arrow_opens_combobox and canvasWidgetSingleLineTextKind(widget.kind) and keyboard.phase == .key_down and keyboard.text.len == 0 and !keyboard.modifiers.hasNavigationModifier()) {
|
|
67
84
|
if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowup")) return .{ .move_caret = .{ .direction = .start, .extend = keyboard.modifiers.shift } };
|
|
68
85
|
if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) return .{ .move_caret = .{ .direction = .end, .extend = keyboard.modifiers.shift } };
|
|
69
86
|
}
|