@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.
- package/build/app.zig +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
//! `ElementOptions.context_menu` (app-declared, Msg-mapped items),
|
|
14
14
|
//! 2. an editable text target: the standard Cut / Copy / Paste /
|
|
15
15
|
//! Select All menu wired to the existing clipboard actions,
|
|
16
|
-
//! 3. the
|
|
17
|
-
//!
|
|
18
|
-
//!
|
|
19
|
-
//!
|
|
16
|
+
//! 3. a terminal target: the standard Copy / Paste menu wired to its
|
|
17
|
+
//! emulator selection and committed-input channel,
|
|
18
|
+
//! 4. the view's live static-text selection: a Copy-only menu.
|
|
19
|
+
//! The zero-code defaults (2 through 4) are presenter-only: without a
|
|
20
|
+
//! native menu they present no synthesized surface (there are no
|
|
21
|
+
//! app-declared items to mount), while their available keyboard paths
|
|
22
|
+
//! remain unchanged.
|
|
20
23
|
//!
|
|
21
24
|
//! Presentation is asynchronous (macOS `popUpMenuPositioningItem` runs a
|
|
22
25
|
//! nested tracking loop): the platform emits a `context_menu_action`
|
|
@@ -40,12 +43,40 @@ pub const default_item_select_all: u32 = 4;
|
|
|
40
43
|
|
|
41
44
|
pub const PendingCanvasWidgetContextMenu = struct {
|
|
42
45
|
window_id: platform.WindowId = 1,
|
|
46
|
+
/// Per-request generation, minted when the request is armed and
|
|
47
|
+
/// echoed back by the platform on the action event. Menus can be
|
|
48
|
+
/// superseded while a dismissal is still in flight (GTK tears the
|
|
49
|
+
/// old popover down one loop turn after the successor presents), so
|
|
50
|
+
/// the token must name the REQUEST, not the widget: a stale token's
|
|
51
|
+
/// event must never resolve — or clear — a successor's pending
|
|
52
|
+
/// request, even when both menus target the same widget.
|
|
43
53
|
token: u64 = 0,
|
|
54
|
+
/// The widget the menu was presented for (selections dispatch
|
|
55
|
+
/// against it; the token above no longer doubles as its id).
|
|
56
|
+
target_id: canvas.ObjectId = 0,
|
|
44
57
|
kind: Kind = .app,
|
|
58
|
+
/// The presented view's label, copied into the request so a
|
|
59
|
+
/// superseded menu's dismissal notice can still name its canvas —
|
|
60
|
+
/// the view may be gone (window closed) by the time the request
|
|
61
|
+
/// resolves, and per-canvas menu state in a raw app needs the
|
|
62
|
+
/// correlation.
|
|
63
|
+
view_label_storage: [platform.max_view_label_bytes]u8 = undefined,
|
|
64
|
+
view_label_len: usize = 0,
|
|
65
|
+
|
|
66
|
+
pub fn viewLabel(self: *const PendingCanvasWidgetContextMenu) []const u8 {
|
|
67
|
+
return self.view_label_storage[0..self.view_label_len];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pub fn setViewLabel(self: *PendingCanvasWidgetContextMenu, label: []const u8) void {
|
|
71
|
+
const len = @min(label.len, self.view_label_storage.len);
|
|
72
|
+
@memcpy(self.view_label_storage[0..len], label[0..len]);
|
|
73
|
+
self.view_label_len = len;
|
|
74
|
+
}
|
|
45
75
|
|
|
46
76
|
pub const Kind = enum {
|
|
47
77
|
app,
|
|
48
78
|
edit_text,
|
|
79
|
+
terminal,
|
|
49
80
|
static_copy,
|
|
50
81
|
};
|
|
51
82
|
};
|
|
@@ -106,23 +137,57 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
106
137
|
.separator = item.separator,
|
|
107
138
|
};
|
|
108
139
|
}
|
|
109
|
-
|
|
140
|
+
switch (try showMenu(self, app, index, .{
|
|
110
141
|
.window_id = input_event.window_id,
|
|
111
|
-
.
|
|
142
|
+
.target_id = widget.id,
|
|
112
143
|
.kind = .app,
|
|
113
|
-
}, point, items[0..count]))
|
|
144
|
+
}, point, items[0..count])) {
|
|
145
|
+
.shown => |shown| {
|
|
146
|
+
// Presentation is asynchronous on GTK (and the
|
|
147
|
+
// snapshot is harmless where the presenter blocks):
|
|
148
|
+
// tell the app WHAT is on the glass, keyed by the
|
|
149
|
+
// request's token, so the eventual selection
|
|
150
|
+
// resolves against the shown items' dispatch
|
|
151
|
+
// payloads — never a tree that rebuilt (reordering
|
|
152
|
+
// or re-mapping items) while the menu was open.
|
|
153
|
+
// The event's fields come from the returned request
|
|
154
|
+
// itself, never `self.views[index]` re-read here:
|
|
155
|
+
// `showMenu` ran the superseded menu's dismissal
|
|
156
|
+
// notice — arbitrary app code that may have closed
|
|
157
|
+
// views and compacted their indices.
|
|
158
|
+
try self.dispatchEvent(app, .{ .canvas_widget_context_menu_shown = .{
|
|
159
|
+
.window_id = shown.window_id,
|
|
160
|
+
.view_label = shown.viewLabel(),
|
|
161
|
+
.target_id = widget.id,
|
|
162
|
+
.token = shown.token,
|
|
163
|
+
.item_count = count,
|
|
164
|
+
} });
|
|
165
|
+
return;
|
|
166
|
+
},
|
|
167
|
+
// The dismissal notice's app code presented a
|
|
168
|
+
// successor that replaced this request (the
|
|
169
|
+
// successor already announced itself), or closed
|
|
170
|
+
// the presenting view outright: announce NOTHING
|
|
171
|
+
// here — and never the anchored fallback, which
|
|
172
|
+
// would mount a surface under the successor's
|
|
173
|
+
// native menu or on a view that no longer exists.
|
|
174
|
+
.superseded, .view_closed => return,
|
|
175
|
+
.refused => {},
|
|
176
|
+
}
|
|
114
177
|
}
|
|
115
178
|
try self.dispatchEvent(app, .{ .canvas_widget_context_menu_request = .{
|
|
116
179
|
.window_id = input_event.window_id,
|
|
117
180
|
.view_label = self.views[index].label,
|
|
118
181
|
.target_id = widget.id,
|
|
182
|
+
.point = point,
|
|
119
183
|
} });
|
|
120
184
|
return;
|
|
121
185
|
}
|
|
122
186
|
|
|
123
|
-
// 2. Editable text
|
|
124
|
-
// the existing clipboard
|
|
125
|
-
// paste lands where the
|
|
187
|
+
// 2/3. Editable text and terminal targets: standard menus
|
|
188
|
+
// wired to the existing clipboard and committed-input
|
|
189
|
+
// paths. Focus the target first so paste lands where the
|
|
190
|
+
// user clicked (macOS behavior).
|
|
126
191
|
if (pointer_event.target) |target| {
|
|
127
192
|
const node_index = self.views[index].canvasWidgetNodeIndexById(target.id) orelse return;
|
|
128
193
|
const widget = self.views[index].widget_layout_nodes[node_index].widget;
|
|
@@ -135,29 +200,44 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
135
200
|
items[2] = .{ .id = default_item_paste, .label = "Paste" };
|
|
136
201
|
items[3] = .{ .separator = true };
|
|
137
202
|
items[4] = .{ .id = default_item_select_all, .label = "Select All", .enabled = widget.text.len > 0 };
|
|
138
|
-
_ = try showMenu(self, index, .{
|
|
203
|
+
_ = try showMenu(self, app, index, .{
|
|
139
204
|
.window_id = input_event.window_id,
|
|
140
|
-
.
|
|
205
|
+
.target_id = target.id,
|
|
141
206
|
.kind = .edit_text,
|
|
142
207
|
}, point, items[0..5]);
|
|
143
208
|
return;
|
|
144
209
|
}
|
|
145
210
|
|
|
146
|
-
|
|
211
|
+
if (widget.kind == .terminal and !widget.state.disabled) {
|
|
212
|
+
if (!has_presenter) return;
|
|
213
|
+
try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromPointer(self, pointer_event);
|
|
214
|
+
const has_selection = if (widget.terminal.grid) |grid| grid.selection_active else false;
|
|
215
|
+
const can_paste = if (widget.terminal.grid) |grid| widget.terminal.pty != 0 and grid.running else false;
|
|
216
|
+
items[0] = .{ .id = default_item_copy, .label = "Copy", .enabled = has_selection };
|
|
217
|
+
items[1] = .{ .id = default_item_paste, .label = "Paste", .enabled = can_paste };
|
|
218
|
+
_ = try showMenu(self, app, index, .{
|
|
219
|
+
.window_id = input_event.window_id,
|
|
220
|
+
.target_id = target.id,
|
|
221
|
+
.kind = .terminal,
|
|
222
|
+
}, point, items[0..2]);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 4. Static text with a live selection: Copy only.
|
|
147
227
|
const selected_id = self.views[index].canvas_widget_selected_text_id;
|
|
148
228
|
if (selected_id != 0 and selected_id == target.id) {
|
|
149
229
|
if (!has_presenter) return;
|
|
150
230
|
items[0] = .{ .id = default_item_copy, .label = "Copy" };
|
|
151
|
-
_ = try showMenu(self, index, .{
|
|
231
|
+
_ = try showMenu(self, app, index, .{
|
|
152
232
|
.window_id = input_event.window_id,
|
|
153
|
-
.
|
|
233
|
+
.target_id = target.id,
|
|
154
234
|
.kind = .static_copy,
|
|
155
235
|
}, point, items[0..1]);
|
|
156
236
|
return;
|
|
157
237
|
}
|
|
158
238
|
}
|
|
159
239
|
|
|
160
|
-
//
|
|
240
|
+
// 5. No menu anywhere on the route: the press-and-hold
|
|
161
241
|
// alternative. Deliver the context press so `UiApp` can
|
|
162
242
|
// dispatch the press target's `on_hold` Msg.
|
|
163
243
|
try self.dispatchEvent(app, .{ .canvas_widget_context_press = .{
|
|
@@ -167,11 +247,66 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
167
247
|
} });
|
|
168
248
|
}
|
|
169
249
|
|
|
170
|
-
///
|
|
171
|
-
///
|
|
172
|
-
///
|
|
173
|
-
///
|
|
174
|
-
|
|
250
|
+
/// A NEW presentation or dispatch replaced the pending request.
|
|
251
|
+
/// An app menu's pending has state beyond the runtime's gate —
|
|
252
|
+
/// UiApp holds a token-keyed snapshot and a pinned build
|
|
253
|
+
/// generation for it, and a raw app may track per-canvas menu
|
|
254
|
+
/// state — and the superseded token can never arrive (the gate
|
|
255
|
+
/// would swallow it), so tell the app the old menu is gone,
|
|
256
|
+
/// named by the view it was presented on. This runs for EVERY
|
|
257
|
+
/// superseding kind: app over app, a default edit/copy menu
|
|
258
|
+
/// over an app menu, and the automation verb's direct dispatch.
|
|
259
|
+
/// Call it AFTER committing the replacement pending: the notice
|
|
260
|
+
/// dispatch is fallible, and the runtime's bookkeeping must
|
|
261
|
+
/// already match the menu the platform accepted.
|
|
262
|
+
pub fn notifySupersededPending(self: *Runtime, app: runtime_api.App(Runtime), superseded: ?PendingCanvasWidgetContextMenu) anyerror!void {
|
|
263
|
+
const pending = superseded orelse return;
|
|
264
|
+
if (pending.kind != .app) return;
|
|
265
|
+
try self.dispatchEvent(app, .{ .canvas_widget_context_menu_dismissed = .{
|
|
266
|
+
.window_id = pending.window_id,
|
|
267
|
+
.view_label = pending.viewLabel(),
|
|
268
|
+
.token = pending.token,
|
|
269
|
+
} });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const ShowMenuOutcome = union(enum) {
|
|
273
|
+
/// The platform accepted and the request is still the
|
|
274
|
+
/// pending truth: announce it
|
|
275
|
+
/// (`canvas_widget_context_menu_shown`).
|
|
276
|
+
shown: PendingCanvasWidgetContextMenu,
|
|
277
|
+
/// The platform refused — not fatal (app-declared menus
|
|
278
|
+
/// fall back to the anchored canvas surface, the zero-code
|
|
279
|
+
/// defaults degrade to their keyboard paths). The old
|
|
280
|
+
/// pending (and its popover, if any) is still the truth.
|
|
281
|
+
refused,
|
|
282
|
+
/// The platform accepted, but the superseded menu's
|
|
283
|
+
/// dismissal notice synchronously presented a SUCCESSOR
|
|
284
|
+
/// that replaced this request. The successor is the truth
|
|
285
|
+
/// and already announced itself: announcing this request
|
|
286
|
+
/// late would overwrite the successor's snapshot with a
|
|
287
|
+
/// menu whose token the action gate no longer accepts,
|
|
288
|
+
/// stranding the successor on live-tree resolution and the
|
|
289
|
+
/// stale pin unreleased.
|
|
290
|
+
superseded,
|
|
291
|
+
/// The platform accepted, but the superseded menu's
|
|
292
|
+
/// dismissal notice CLOSED the presenting view. The request
|
|
293
|
+
/// can never resolve (its action would clear the token and
|
|
294
|
+
/// silently drop on the view lookup — or never arrive at
|
|
295
|
+
/// all if the window died with it), so it is disarmed here:
|
|
296
|
+
/// announce nothing, mount nothing.
|
|
297
|
+
view_closed,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/// Present `request` natively. Callers must describe the
|
|
301
|
+
/// presented menu from the returned `.shown` request, not from
|
|
302
|
+
/// `self.views[view_index]`: the superseded menu's dismissal
|
|
303
|
+
/// notice below runs arbitrary app code that may close views
|
|
304
|
+
/// and compact their indices — or present a successor menu
|
|
305
|
+
/// (see `ShowMenuOutcome.superseded`).
|
|
306
|
+
fn showMenu(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, request: PendingCanvasWidgetContextMenu, point: geometry.PointF, items: []const platform.ContextMenuItem) anyerror!ShowMenuOutcome {
|
|
307
|
+
var pending = request;
|
|
308
|
+
pending.token = nextContextMenuToken(self);
|
|
309
|
+
pending.setViewLabel(self.views[view_index].label);
|
|
175
310
|
self.options.platform.services.showContextMenu(.{
|
|
176
311
|
.window_id = pending.window_id,
|
|
177
312
|
.view_label = self.views[view_index].label,
|
|
@@ -182,10 +317,25 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
182
317
|
if (err != error.UnsupportedService) {
|
|
183
318
|
context_menu_log.warn("context menu presentation failed: {s}", .{@errorName(err)});
|
|
184
319
|
}
|
|
185
|
-
|
|
320
|
+
// Presentation refused: nothing superseded — the old
|
|
321
|
+
// pending (and its popover, if any) is still the truth.
|
|
322
|
+
return .refused;
|
|
186
323
|
};
|
|
324
|
+
// The platform accepted: commit the replacement BEFORE the
|
|
325
|
+
// fallible superseded-notice dispatch, so the runtime's
|
|
326
|
+
// expected token always matches the menu on the glass.
|
|
327
|
+
const superseded = self.canvas_widget_context_menu_pending;
|
|
187
328
|
self.canvas_widget_context_menu_pending = pending;
|
|
188
|
-
|
|
329
|
+
try notifySupersededPending(self, app, superseded);
|
|
330
|
+
const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == pending.token else false;
|
|
331
|
+
if (!still_armed) return .superseded;
|
|
332
|
+
// Still armed, but the notice may have closed the view the
|
|
333
|
+
// menu presented on: disarm the unresolvable request.
|
|
334
|
+
if (runtimeFindViewIndex(self, pending.window_id, pending.viewLabel()) == null) {
|
|
335
|
+
self.canvas_widget_context_menu_pending = null;
|
|
336
|
+
return .view_closed;
|
|
337
|
+
}
|
|
338
|
+
return .{ .shown = pending };
|
|
189
339
|
}
|
|
190
340
|
|
|
191
341
|
/// The platform reported the menu outcome: resolve the pending
|
|
@@ -195,19 +345,48 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
195
345
|
/// directly through the same paths the keyboard shortcuts use.
|
|
196
346
|
pub fn dispatchContextMenuAction(self: *Runtime, app: runtime_api.App(Runtime), event: platform.ContextMenuActionEvent) anyerror!void {
|
|
197
347
|
const pending = self.canvas_widget_context_menu_pending orelse return;
|
|
198
|
-
|
|
348
|
+
// Token gate BEFORE the clear: an event carrying a stale
|
|
349
|
+
// token belongs to a superseded request (its deferred
|
|
350
|
+
// dismissal outlived a re-click's replacement menu) and is
|
|
351
|
+
// swallowed — it must never clear, let alone resolve, the
|
|
352
|
+
// successor's pending request. Windows cannot produce a
|
|
353
|
+
// stale event (TrackPopupMenu blocks the loop thread and
|
|
354
|
+
// emits inline from the moved-out request, so a second
|
|
355
|
+
// request never dispatches mid-menu); macOS cannot either
|
|
356
|
+
// (each presentation block captures its own token and
|
|
357
|
+
// popUpMenuPositioningItem's nested tracking loop blocks
|
|
358
|
+
// the main queue); GTK popovers are asynchronous and CAN.
|
|
199
359
|
if (pending.window_id != event.window_id or pending.token != event.token) return;
|
|
200
|
-
|
|
360
|
+
self.canvas_widget_context_menu_pending = null;
|
|
361
|
+
if (event.item_id == 0) {
|
|
362
|
+
// Dismissed without a selection. App menus tell the app:
|
|
363
|
+
// UiApp disarms the token's presented-items snapshot and
|
|
364
|
+
// releases the build storage pinned under it.
|
|
365
|
+
if (pending.kind == .app) {
|
|
366
|
+
try self.dispatchEvent(app, .{ .canvas_widget_context_menu_dismissed = .{
|
|
367
|
+
.window_id = event.window_id,
|
|
368
|
+
.view_label = event.view_label,
|
|
369
|
+
.token = pending.token,
|
|
370
|
+
} });
|
|
371
|
+
}
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
201
374
|
const index = runtimeFindViewIndex(self, event.window_id, event.view_label) orelse return;
|
|
202
375
|
|
|
203
376
|
switch (pending.kind) {
|
|
204
|
-
.app => try self.dispatchEvent(app, .{
|
|
205
|
-
.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
377
|
+
.app => try self.dispatchEvent(app, .{
|
|
378
|
+
.canvas_widget_context_menu = .{
|
|
379
|
+
.window_id = event.window_id,
|
|
380
|
+
.view_label = self.views[index].label,
|
|
381
|
+
.target_id = pending.target_id,
|
|
382
|
+
.item_index = event.item_id - 1,
|
|
383
|
+
// The shown snapshot's key: UiApp resolves the
|
|
384
|
+
// selection from what was presented under this token.
|
|
385
|
+
.token = pending.token,
|
|
386
|
+
},
|
|
387
|
+
}),
|
|
388
|
+
.edit_text => try applyDefaultEditAction(self, app, index, pending.target_id, event.item_id),
|
|
389
|
+
.terminal => try applyDefaultTerminalAction(self, app, index, pending.target_id, event.item_id),
|
|
211
390
|
.static_copy => {
|
|
212
391
|
if (event.item_id != default_item_copy) return;
|
|
213
392
|
const text = self.views[index].canvasWidgetCopyText() orelse return;
|
|
@@ -216,6 +395,14 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
216
395
|
}
|
|
217
396
|
}
|
|
218
397
|
|
|
398
|
+
/// Mint the next per-request correlation token. Never zero, so a
|
|
399
|
+
/// zero-token event can never match an armed request.
|
|
400
|
+
pub fn nextContextMenuToken(self: *Runtime) u64 {
|
|
401
|
+
self.canvas_widget_context_menu_token +%= 1;
|
|
402
|
+
if (self.canvas_widget_context_menu_token == 0) self.canvas_widget_context_menu_token = 1;
|
|
403
|
+
return self.canvas_widget_context_menu_token;
|
|
404
|
+
}
|
|
405
|
+
|
|
219
406
|
fn applyDefaultEditAction(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, target_id: canvas.ObjectId, item_id: u32) anyerror!void {
|
|
220
407
|
switch (item_id) {
|
|
221
408
|
default_item_copy => {
|
|
@@ -257,6 +444,53 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
257
444
|
}
|
|
258
445
|
}
|
|
259
446
|
|
|
447
|
+
fn applyDefaultTerminalAction(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, target_id: canvas.ObjectId, item_id: u32) anyerror!void {
|
|
448
|
+
const node_index = self.views[view_index].canvasWidgetNodeIndexById(target_id) orelse return;
|
|
449
|
+
const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
|
|
450
|
+
if (widget.kind != .terminal or widget.state.disabled) return;
|
|
451
|
+
|
|
452
|
+
switch (item_id) {
|
|
453
|
+
default_item_copy => {
|
|
454
|
+
const grid = widget.terminal.grid orelse return;
|
|
455
|
+
if (!grid.selection_active) return;
|
|
456
|
+
self.writeClipboard(grid.selection_text) catch return;
|
|
457
|
+
},
|
|
458
|
+
default_item_paste => {
|
|
459
|
+
if (widget.terminal.pty == 0) return;
|
|
460
|
+
const grid = widget.terminal.grid orelse return;
|
|
461
|
+
// The native menu resolves asynchronously on GTK:
|
|
462
|
+
// a session that was live when the menu opened may
|
|
463
|
+
// have exited before Paste is chosen. Revalidate at
|
|
464
|
+
// action time so dead-session input cannot fall
|
|
465
|
+
// through to UiApp's app-level `on_text` seam.
|
|
466
|
+
if (!grid.running) return;
|
|
467
|
+
var paste_buffer: [platform.max_clipboard_data_bytes]u8 = undefined;
|
|
468
|
+
const text = self.readClipboard(&paste_buffer) catch return;
|
|
469
|
+
if (text.len == 0) return;
|
|
470
|
+
// Terminals deliberately stay outside the TextBuffer
|
|
471
|
+
// editor pipeline. Mark this committed payload as a
|
|
472
|
+
// PASTE so UiApp routes it through the emulator's
|
|
473
|
+
// dedicated paste encoder, not the ordinary typing
|
|
474
|
+
// path: bracketed-paste framing, newline conversion,
|
|
475
|
+
// and unsafe-control stripping are all provenance-
|
|
476
|
+
// sensitive terminal behavior.
|
|
477
|
+
try self.dispatchEvent(app, .{ .canvas_widget_keyboard = .{
|
|
478
|
+
.window_id = self.views[view_index].window_id,
|
|
479
|
+
.view_label = self.views[view_index].label,
|
|
480
|
+
.keyboard = .{
|
|
481
|
+
.phase = .text_input,
|
|
482
|
+
.focused_id = target_id,
|
|
483
|
+
.text = text,
|
|
484
|
+
.edit = .{ .insert_text = text },
|
|
485
|
+
},
|
|
486
|
+
.terminal_paste = true,
|
|
487
|
+
.standalone = true,
|
|
488
|
+
} });
|
|
489
|
+
},
|
|
490
|
+
else => {},
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
260
494
|
/// A synthesized key-down keyboard event addressed at the editable
|
|
261
495
|
/// widget, shaped like the routed events the clipboard shortcuts
|
|
262
496
|
/// stamp their edits onto.
|
|
@@ -275,6 +509,9 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
275
509
|
/// edits perform, so runtime widget and app model stay in sync.
|
|
276
510
|
fn applyEditKeyboardEvent(self: *Runtime, app: runtime_api.App(Runtime), keyboard_event: runtime_api.CanvasWidgetKeyboardEvent) anyerror!void {
|
|
277
511
|
var event = keyboard_event;
|
|
512
|
+
// No gpu-surface input cycle wraps a context-menu edit: mark
|
|
513
|
+
// it standalone so the ui-app hover drain runs at its tail.
|
|
514
|
+
event.standalone = true;
|
|
278
515
|
try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &event);
|
|
279
516
|
try self.dispatchEvent(app, .{ .canvas_widget_keyboard = event });
|
|
280
517
|
}
|