@native-sdk/cli 0.7.0 → 0.7.1

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 (52) hide show
  1. package/build.zig +65 -91
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/text.ts +25 -14
  6. package/packages/core/src/checker.ts +39 -0
  7. package/packages/core/src/emitter.ts +125 -1
  8. package/skill-data/native-ui/SKILL.md +9 -7
  9. package/src/platform/macos/appkit_host.m +25 -1
  10. package/src/platform/macos/cef_host.mm +24 -2
  11. package/src/platform/macos/root.zig +13 -0
  12. package/src/primitives/canvas/code.zig +451 -33
  13. package/src/primitives/canvas/code_tests.zig +855 -5
  14. package/src/primitives/canvas/events.zig +111 -1
  15. package/src/primitives/canvas/markdown_tests.zig +17 -18
  16. package/src/primitives/canvas/root.zig +4 -0
  17. package/src/primitives/canvas/text.zig +6 -0
  18. package/src/primitives/canvas/ui.zig +108 -29
  19. package/src/primitives/canvas/ui_markup.zig +23 -9
  20. package/src/primitives/canvas/ui_markup_compiled.zig +13 -0
  21. package/src/primitives/canvas/ui_markup_compiled_tests.zig +12 -0
  22. package/src/primitives/canvas/ui_markup_contract.zig +8 -1
  23. package/src/primitives/canvas/ui_markup_view.zig +16 -0
  24. package/src/primitives/canvas/ui_markup_view_tests.zig +71 -5
  25. package/src/primitives/canvas/ui_schema.zig +13 -0
  26. package/src/primitives/canvas/ui_schema_tests.zig +9 -7
  27. package/src/primitives/canvas/ui_tests.zig +26 -0
  28. package/src/primitives/canvas/widget_invalidation.zig +1 -0
  29. package/src/primitives/canvas/widget_metrics.zig +10 -5
  30. package/src/primitives/canvas/widget_render.zig +660 -39
  31. package/src/primitives/canvas/widget_render_controls.zig +4 -4
  32. package/src/primitives/canvas/widget_runtime.zig +2 -0
  33. package/src/primitives/canvas/widget_text_input.zig +165 -8
  34. package/src/primitives/canvas/widget_tree.zig +6 -5
  35. package/src/primitives/canvas/widgets.zig +25 -0
  36. package/src/runtime/canvas_budget_edge_tests.zig +3 -2
  37. package/src/runtime/canvas_limits.zig +13 -6
  38. package/src/runtime/canvas_widget_clipboard_tests.zig +7 -4
  39. package/src/runtime/canvas_widget_context_menu.zig +7 -2
  40. package/src/runtime/canvas_widget_event_tests.zig +18 -14
  41. package/src/runtime/canvas_widget_events.zig +51 -20
  42. package/src/runtime/canvas_widget_runtime.zig +105 -4
  43. package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
  44. package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
  45. package/src/runtime/canvas_widget_state.zig +27 -0
  46. package/src/runtime/canvas_widget_text_tests.zig +326 -0
  47. package/src/runtime/core.zig +15 -5
  48. package/src/runtime/gpu_surface_events.zig +12 -12
  49. package/src/runtime/view.zig +54 -16
  50. package/src/runtime/view_widget_scroll.zig +48 -18
  51. package/src/runtime/view_widget_text.zig +54 -13
  52. package/src/runtime/window_view_runtime.zig +9 -0
@@ -78,6 +78,52 @@ test "the builder's presented-text store mirrors the per-view draw-text budget"
78
78
  );
79
79
  }
80
80
 
81
+ test "closing an earlier view transfers a later view's expanded text storage" {
82
+ const TestApp = struct {
83
+ fn app(self: *@This()) App {
84
+ return .{ .context = self, .name = "gpu-widget-expanded-storage-compaction", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
85
+ }
86
+ };
87
+
88
+ const harness = try TestHarness().create(std.testing.allocator, .{});
89
+ defer harness.destroy(std.testing.allocator);
90
+ harness.null_platform.gpu_surfaces = true;
91
+ var app_state: TestApp = .{};
92
+ try harness.start(app_state.app());
93
+
94
+ for ([_][]const u8{ "canvas-a", "canvas-b" }) |label| {
95
+ _ = try harness.runtime.createView(.{
96
+ .window_id = 1,
97
+ .label = label,
98
+ .kind = .gpu_surface,
99
+ .frame = geometry.RectF.init(0, 0, 240, 160),
100
+ });
101
+ }
102
+ const ordinary = canvas.Widget{ .id = 2, .kind = .text, .text = "ordinary" };
103
+ var ordinary_nodes: [1]canvas.WidgetLayoutNode = undefined;
104
+ const ordinary_layout = try canvas.layoutWidgetTree(ordinary, geometry.RectF.init(0, 0, 240, 160), &ordinary_nodes);
105
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas-a", ordinary_layout);
106
+
107
+ const editor = canvas.Widget{
108
+ .id = 3,
109
+ .kind = .textarea,
110
+ .text = "expanded",
111
+ .text_no_wrap = true,
112
+ .code_editor = true,
113
+ };
114
+ var editor_nodes: [1]canvas.WidgetLayoutNode = undefined;
115
+ const editor_layout = try canvas.layoutWidgetTree(editor, geometry.RectF.init(0, 0, 240, 160), &editor_nodes);
116
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas-b", editor_layout);
117
+ try std.testing.expect(harness.runtime.views[0].widget_text_bytes_heap_owned);
118
+ try std.testing.expect(harness.runtime.views[1].widget_text_bytes_heap_owned);
119
+
120
+ try harness.runtime.closeView(1, "canvas-a");
121
+ try std.testing.expectEqual(@as(usize, 1), harness.runtime.view_count);
122
+ try std.testing.expectEqualStrings("canvas-b", harness.runtime.views[0].label);
123
+ try std.testing.expect(harness.runtime.views[0].widget_text_bytes_heap_owned);
124
+ try std.testing.expectEqualStrings("expanded", harness.runtime.views[0].widgetLayoutTree().nodes[0].widget.text);
125
+ }
126
+
81
127
  test "runtime exposes retained canvas widget text geometry" {
82
128
  const TestApp = struct {
83
129
  fn app(self: *@This()) App {
@@ -3801,6 +3847,123 @@ test "maximal numbered code fits the retained text budget" {
3801
3847
  try std.testing.expect(found_source);
3802
3848
  }
3803
3849
 
3850
+ test "editable code owns plain Tab and stamps its inferred indentation edit" {
3851
+ const TestApp = struct {
3852
+ edit_count: usize = 0,
3853
+ insertion: [8]u8 = @splat(0),
3854
+ insertion_len: usize = 0,
3855
+
3856
+ fn app(self: *@This()) App {
3857
+ return .{
3858
+ .context = self,
3859
+ .name = "gpu-widget-code-tab",
3860
+ .source = platform.WebViewSource.html("<h1>Hello</h1>"),
3861
+ .event_fn = event,
3862
+ };
3863
+ }
3864
+
3865
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
3866
+ _ = runtime;
3867
+ const self: *@This() = @ptrCast(@alignCast(context));
3868
+ switch (event_value) {
3869
+ .canvas_widget_keyboard => |keyboard_event| {
3870
+ const edit = keyboard_event.keyboard.edit orelse return;
3871
+ switch (edit) {
3872
+ .insert_text => |text| {
3873
+ self.edit_count += 1;
3874
+ self.insertion_len = @min(text.len, self.insertion.len);
3875
+ @memcpy(self.insertion[0..self.insertion_len], text[0..self.insertion_len]);
3876
+ },
3877
+ else => {},
3878
+ }
3879
+ },
3880
+ else => {},
3881
+ }
3882
+ }
3883
+ };
3884
+
3885
+ const harness = try TestHarness().create(std.testing.allocator, .{});
3886
+ defer harness.destroy(std.testing.allocator);
3887
+ harness.null_platform.gpu_surfaces = true;
3888
+ var app_state: TestApp = .{};
3889
+ const app = app_state.app();
3890
+ try harness.start(app);
3891
+ _ = try harness.runtime.createView(.{
3892
+ .window_id = 1,
3893
+ .label = "canvas",
3894
+ .kind = .gpu_surface,
3895
+ .frame = geometry.RectF.init(0, 0, 320, 180),
3896
+ });
3897
+
3898
+ const source = "if (ready) {\n run();\n}\n";
3899
+ const children = [_]canvas.Widget{
3900
+ .{
3901
+ .id = 3,
3902
+ .kind = .button,
3903
+ .frame = geometry.RectF.init(240, 16, 68, 32),
3904
+ .text = "Run",
3905
+ },
3906
+ .{
3907
+ .id = 2,
3908
+ .kind = .textarea,
3909
+ .code_editor = true,
3910
+ .text_no_wrap = true,
3911
+ .frame = geometry.RectF.init(12, 16, 220, 100),
3912
+ .text = source,
3913
+ .text_selection = canvas.TextSelection.collapsed(source.len),
3914
+ },
3915
+ };
3916
+ var nodes: [3]canvas.WidgetLayoutNode = undefined;
3917
+ const layout = try canvas.layoutWidgetTree(
3918
+ .{ .id = 1, .kind = .stack, .children = &children },
3919
+ geometry.RectF.init(0, 0, 320, 180),
3920
+ &nodes,
3921
+ );
3922
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
3923
+
3924
+ // Tab from the preceding button enters the editor as focus
3925
+ // traversal and must not indent on that same physical gesture.
3926
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3927
+ .window_id = 1,
3928
+ .label = "canvas",
3929
+ .kind = .pointer_down,
3930
+ .x = 260,
3931
+ .y = 28,
3932
+ } });
3933
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3934
+ .window_id = 1,
3935
+ .label = "canvas",
3936
+ .kind = .key_down,
3937
+ .key = "tab",
3938
+ } });
3939
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
3940
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
3941
+ try std.testing.expectEqualStrings(source, retained.nodes[2].widget.text);
3942
+ try std.testing.expectEqual(@as(usize, 0), app_state.edit_count);
3943
+ try std.testing.expect(harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
3944
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3945
+ .window_id = 1,
3946
+ .label = "canvas",
3947
+ .kind = .key_up,
3948
+ .key = "tab",
3949
+ } });
3950
+ try std.testing.expect(!harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
3951
+
3952
+ // Once focused, plain Tab is an ordinary stamped edit. Four-space
3953
+ // indentation wins from the source's existing leading whitespace.
3954
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3955
+ .window_id = 1,
3956
+ .label = "canvas",
3957
+ .kind = .key_down,
3958
+ .key = "tab",
3959
+ } });
3960
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
3961
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
3962
+ try std.testing.expectEqualStrings("if (ready) {\n run();\n}\n ", retained.nodes[2].widget.text);
3963
+ try std.testing.expectEqual(@as(usize, 1), app_state.edit_count);
3964
+ try std.testing.expectEqualStrings(" ", app_state.insertion[0..app_state.insertion_len]);
3965
+ }
3966
+
3804
3967
  /// Scan the widget's frame for a pointer location whose caret offset is
3805
3968
  /// exactly `target`, so multi-click tests aim at text offsets without
3806
3969
  /// hard-coding font metrics.
@@ -3833,6 +3996,93 @@ fn retainedTextSelection(harness: *TestHarness(), node_index: usize) !canvas.Tex
3833
3996
  return retained.nodes[node_index].widget.text_selection orelse error.TestExpectedSelection;
3834
3997
  }
3835
3998
 
3999
+ test "multi-click chains stay on one target and one physical pointer" {
4000
+ const TestApp = struct {
4001
+ fn app(self: *@This()) App {
4002
+ return .{ .context = self, .name = "gpu-widget-click-chain-identity", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
4003
+ }
4004
+ };
4005
+
4006
+ const harness = try TestHarness().create(std.testing.allocator, .{});
4007
+ defer harness.destroy(std.testing.allocator);
4008
+ harness.null_platform.gpu_surfaces = true;
4009
+ var app_state: TestApp = .{};
4010
+ const app = app_state.app();
4011
+ try harness.start(app);
4012
+
4013
+ _ = try harness.runtime.createView(.{
4014
+ .window_id = 1,
4015
+ .label = "canvas",
4016
+ .kind = .gpu_surface,
4017
+ .frame = geometry.RectF.init(0, 0, 320, 200),
4018
+ });
4019
+ const nodes = [_]canvas.WidgetLayoutNode{
4020
+ .{
4021
+ .widget = .{ .id = 2, .kind = .button, .text = "First" },
4022
+ .frame = geometry.RectF.init(0, 0, 20, 24),
4023
+ .depth = 0,
4024
+ },
4025
+ .{
4026
+ .widget = .{ .id = 3, .kind = .button, .text = "Second" },
4027
+ .frame = geometry.RectF.init(20, 0, 20, 24),
4028
+ .depth = 0,
4029
+ },
4030
+ };
4031
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", .{ .nodes = &nodes });
4032
+
4033
+ const ms = std.time.ns_per_ms;
4034
+ const clicks = [_]struct { kind: platform.GpuSurfaceInputKind, timestamp_ns: u64, x: f32, pointer_id: u64 }{
4035
+ .{ .kind = .pointer_down, .timestamp_ns = 1_000 * ms, .x = 19, .pointer_id = 11 },
4036
+ .{ .kind = .pointer_up, .timestamp_ns = 1_030 * ms, .x = 19, .pointer_id = 11 },
4037
+ .{ .kind = .pointer_down, .timestamp_ns = 1_100 * ms, .x = 21, .pointer_id = 11 },
4038
+ };
4039
+ for (clicks) |click| {
4040
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4041
+ .window_id = 1,
4042
+ .label = "canvas",
4043
+ .kind = click.kind,
4044
+ .timestamp_ns = click.timestamp_ns,
4045
+ .pointer_id = click.pointer_id,
4046
+ .x = click.x,
4047
+ .y = 12,
4048
+ } });
4049
+ }
4050
+ try std.testing.expectEqual(@as(u8, 1), harness.runtime.views[0].canvas_widget_click_count);
4051
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_click_target_id);
4052
+
4053
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4054
+ .window_id = 1,
4055
+ .label = "canvas",
4056
+ .kind = .pointer_up,
4057
+ .timestamp_ns = 1_130 * ms,
4058
+ .pointer_id = 11,
4059
+ .x = 21,
4060
+ .y = 12,
4061
+ } });
4062
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4063
+ .window_id = 1,
4064
+ .label = "canvas",
4065
+ .kind = .pointer_down,
4066
+ .timestamp_ns = 1_200 * ms,
4067
+ .pointer_id = 11,
4068
+ .x = 22,
4069
+ .y = 12,
4070
+ } });
4071
+ try std.testing.expectEqual(@as(u8, 2), harness.runtime.views[0].canvas_widget_click_count);
4072
+
4073
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4074
+ .window_id = 1,
4075
+ .label = "canvas",
4076
+ .kind = .pointer_down,
4077
+ .timestamp_ns = 1_300 * ms,
4078
+ .pointer_id = 12,
4079
+ .x = 22,
4080
+ .y = 12,
4081
+ } });
4082
+ try std.testing.expectEqual(@as(u8, 1), harness.runtime.views[0].canvas_widget_click_count);
4083
+ try std.testing.expectEqual(@as(u64, 12), harness.runtime.views[0].canvas_widget_click_pointer_id);
4084
+ }
4085
+
3836
4086
  test "Shift-click extends a textarea selection from the placed caret" {
3837
4087
  const TestApp = struct {
3838
4088
  fn app(self: *@This()) App {
@@ -4345,3 +4595,79 @@ test "runtime scrolls single-line fields horizontally to keep the caret visible"
4345
4595
  try std.testing.expectEqualStrings("short", retained.nodes[1].widget.text);
4346
4596
  try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value);
4347
4597
  }
4598
+
4599
+ test "runtime scrolls editable no-wrap code horizontally and retains both axes" {
4600
+ const TestApp = struct {
4601
+ fn app(self: *@This()) App {
4602
+ return .{ .context = self, .name = "gpu-widget-code-editor-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
4603
+ }
4604
+ };
4605
+
4606
+ const harness = try TestHarness().create(std.testing.allocator, .{});
4607
+ defer harness.destroy(std.testing.allocator);
4608
+ harness.null_platform.gpu_surfaces = true;
4609
+ var app_state: TestApp = .{};
4610
+ const app = app_state.app();
4611
+ try harness.start(app);
4612
+
4613
+ _ = try harness.runtime.createView(.{
4614
+ .window_id = 1,
4615
+ .label = "canvas",
4616
+ .kind = .gpu_surface,
4617
+ .frame = geometry.RectF.init(0, 0, 260, 160),
4618
+ });
4619
+
4620
+ const editor = canvas.Widget{
4621
+ .id = 2,
4622
+ .kind = .textarea,
4623
+ .code_editor = true,
4624
+ .code_line_number_digits = 2,
4625
+ .text_no_wrap = true,
4626
+ .frame = geometry.RectF.init(12, 16, 120, 72),
4627
+ .semantics = .{ .label = "Source" },
4628
+ };
4629
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
4630
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{editor} }, geometry.RectF.init(0, 0, 260, 160), &nodes);
4631
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
4632
+
4633
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4634
+ .window_id = 1,
4635
+ .label = "canvas",
4636
+ .kind = .pointer_down,
4637
+ .x = 20,
4638
+ .y = 30,
4639
+ } });
4640
+
4641
+ // The pinned line-number gutter is outside the source viewport and must
4642
+ // not manufacture a horizontal range of its own.
4643
+ try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 2 0 40");
4644
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4645
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value_x);
4646
+
4647
+ _ = try harness.runtime.editCanvasWidgetText(
4648
+ 1,
4649
+ "canvas",
4650
+ 2,
4651
+ .{ .insert_text = "const deliberately_long_identifier = another_deliberately_long_identifier;" },
4652
+ );
4653
+
4654
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4655
+ try std.testing.expect(retained.nodes[1].widget.value_x > 0);
4656
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value);
4657
+ const viewport = canvas.textInputViewportForWidget(retained.nodes[1].widget, .{}).?;
4658
+ const geometry_value = try harness.runtime.canvasWidgetTextGeometry(1, "canvas", 2);
4659
+ const caret = geometry_value.caret_bounds.?;
4660
+ try std.testing.expect(caret.x >= viewport.x - 0.001);
4661
+ try std.testing.expect(caret.maxX() <= viewport.maxX() + 0.001);
4662
+
4663
+ var rebuild_nodes: [2]canvas.WidgetLayoutNode = undefined;
4664
+ const rebuild = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{editor} }, geometry.RectF.init(0, 0, 260, 160), &rebuild_nodes);
4665
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", rebuild);
4666
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4667
+ try std.testing.expect(retained.nodes[1].widget.value_x > 0);
4668
+
4669
+ _ = try harness.runtime.editCanvasWidgetText(1, "canvas", 2, .{ .move_caret = .{ .direction = .start } });
4670
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4671
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), retained.nodes[1].widget.text_selection.?);
4672
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value_x);
4673
+ }
@@ -183,7 +183,8 @@ pub const Runtime = struct {
183
183
  options: Options,
184
184
  /// The allocator that owns every runtime-lifetime heap allocation
185
185
  /// (registered canvas font bytes, registered canvas image slot
186
- /// buffers, adopted media-surface texture buffers). Captured from
186
+ /// buffers, adopted media-surface texture buffers, and expanded live-view
187
+ /// text/history pools). Captured from
187
188
  /// `Options.allocator` at init precisely
188
189
  /// because `options` is public and mutable: allocation and free of
189
190
  /// owned storage can be a whole runtime lifetime apart, and they
@@ -517,10 +518,10 @@ pub const Runtime = struct {
517
518
  canvas.bumpTextMeasureGeneration();
518
519
  }
519
520
 
520
- /// Release the runtime's heap-owned on-demand storage (registered
521
- /// canvas font bytes, registered canvas image slot buffers, and
522
- /// adopted media-surface texture buffers, allocated from the
523
- /// init-frozen `owned_allocator`), return each registered font's
521
+ /// Release the runtime's heap-owned on-demand storage (expanded live-view
522
+ /// text/history pools, registered canvas font bytes, registered canvas
523
+ /// image slot buffers, and adopted media-surface texture buffers,
524
+ /// allocated from the init-frozen `owned_allocator`), return each registered font's
524
525
  /// host-side registration (through the unregister owner captured
525
526
  /// into the entry at registration time — host font state is
526
527
  /// per-process, this runtime's ids are not, and live `options` may
@@ -537,6 +538,15 @@ pub const Runtime = struct {
537
538
  /// host) call it to return the storage.
538
539
  pub fn deinit(self: *Runtime) void {
539
540
  self.disarmMediaSurfaceWakes();
541
+ for (self.views[0..self.view_count]) |*view| {
542
+ if (view.widget_text_bytes_heap_owned) self.owned_allocator.free(view.widget_text_bytes);
543
+ if (view.canvas_widget_text_history_bytes_heap_owned) self.owned_allocator.free(view.canvas_widget_text_history_bytes);
544
+ view.widget_text_bytes = &.{};
545
+ view.widget_text_bytes_heap_owned = false;
546
+ view.canvas_widget_text_history_bytes = &.{};
547
+ view.canvas_widget_text_history_bytes_heap_owned = false;
548
+ }
549
+ self.view_count = 0;
540
550
  if (self.targetless_ime_preedit.len > 0) {
541
551
  self.owned_allocator.free(self.targetless_ime_preedit);
542
552
  self.targetless_ime_preedit = &.{};
@@ -353,30 +353,30 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
353
353
  self.targetless_ime_preedit_label[0..self.targetless_ime_preedit_label_len],
354
354
  input_event.label,
355
355
  );
356
- // A Tab key-down that moved focus INTO a live terminal is a
357
- // focus gesture for its whole physical lifetime. Suppress
358
- // its auto-repeats and release before any widget pass can
359
- // reinterpret them against the newly focused terminal.
360
- const terminal_focus_entry_tab_suppressed =
361
- CanvasWidgetEventMethods().consumeCanvasWidgetTerminalFocusEntryTab(self, input_event);
356
+ // A Tab key-down that moved focus INTO a Tab-owning editor is
357
+ // a focus gesture for its whole physical lifetime. Suppress
358
+ // repeats and release before a live terminal or editable code
359
+ // can reinterpret them as input.
360
+ const tab_input_focus_entry_suppressed =
361
+ CanvasWidgetEventMethods().consumeCanvasWidgetTabInputFocusEntry(self, input_event);
362
362
  // Terminal Paste owns its matching physical V release even
363
363
  // when Command/Ctrl came up first. Classify it before focus,
364
364
  // routing, or app fallbacks can reinterpret the orphan.
365
365
  const terminal_paste_release_suppressed =
366
366
  CanvasWidgetEventMethods().consumeCanvasWidgetTerminalPasteKeyLifetime(self, input_event);
367
- const terminal_key_lifetime_suppressed =
368
- terminal_focus_entry_tab_suppressed or terminal_paste_release_suppressed;
369
- const keyboard_dismissed_id = if (targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
367
+ const widget_key_lifetime_suppressed =
368
+ tab_input_focus_entry_suppressed or terminal_paste_release_suppressed;
369
+ const keyboard_dismissed_id = if (targetless_composition_owns_keys or widget_key_lifetime_suppressed)
370
370
  0
371
371
  else
372
372
  try CanvasWidgetEventMethods().dismissCanvasWidgetSurfaceFromKeyboardInput(self, input_event);
373
373
  if (keyboard_dismissed_id != 0) dismissed_surface_id = keyboard_dismissed_id;
374
374
  const widget_surface_dismissed = keyboard_dismissed_id != 0;
375
- const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
375
+ const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
376
376
  false
377
377
  else
378
378
  try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromKeyboardInput(self, input_event);
379
- var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
379
+ var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
380
380
  null
381
381
  else
382
382
  CanvasWidgetEventMethods().routeCanvasWidgetKeyboardInput(self, input_event, &self.widget_event_route_entries) catch |err| switch (err) {
@@ -676,7 +676,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
676
676
  try self.dispatchEvent(app, .{ .canvas_widget_keyboard = followup });
677
677
  }
678
678
  } else if ((input_event.kind == .key_down or input_event.kind == .key_up) and
679
- !widget_surface_dismissed and !terminal_key_lifetime_suppressed)
679
+ !widget_surface_dismissed and !widget_key_lifetime_suppressed)
680
680
  {
681
681
  // No focused widget routed this key (nothing is
682
682
  // focused, or the focused id is gone from the tree): the
@@ -29,9 +29,7 @@ const max_canvas_visual_effects_per_view = canvas_limits.max_canvas_visual_effec
29
29
  const max_canvas_text_layouts_per_view = canvas_limits.max_canvas_text_layouts_per_view;
30
30
  const max_canvas_widget_nodes_per_view = canvas_limits.max_canvas_widget_nodes_per_view;
31
31
  const max_canvas_widget_semantics_per_view = canvas_limits.max_canvas_widget_semantics_per_view;
32
- const max_canvas_widget_text_bytes_per_view = canvas_limits.max_canvas_widget_text_bytes_per_view;
33
32
  const max_canvas_widget_source_text_entries_per_view = canvas_limits.max_canvas_widget_source_text_entries_per_view;
34
- const max_canvas_widget_text_history_bytes_per_view = canvas_limits.max_canvas_widget_text_history_bytes_per_view;
35
33
  const max_canvas_widget_text_history_entries_per_view = canvas_limits.max_canvas_widget_text_history_entries_per_view;
36
34
 
37
35
  const CanvasWidgetSourceTextEntry = canvas_widget_runtime.CanvasWidgetSourceTextEntry;
@@ -161,12 +159,10 @@ pub fn clearImeGraceOnViewBlur(runtime: anytype, view: *RuntimeView) void {
161
159
  // otherwise leave the carry armed to swallow the refocused view's
162
160
  // first unrelated commit.
163
161
  view.canvas_widget_claimed_key_grace = .none;
164
- // A Tab that entered a live terminal suppresses its repeats and
165
- // release until the physical key comes up. If the view blurs first,
166
- // that release may never arrive here; retire the latch with the
167
- // other view-local input graces so a later Tab is never mistaken
168
- // for the tail of the old gesture.
169
- view.canvas_widget_terminal_focus_entry_tab_held = false;
162
+ // A Tab that entered a Tab-owning editor (live terminal or editable
163
+ // code) suppresses its repeats and release until the physical key
164
+ // comes up. If the view blurs first, retire the latch here.
165
+ view.canvas_widget_tab_input_focus_entry_held = false;
170
166
  // Same physical-lifetime rule for terminal Paste: a native menu can
171
167
  // synthesize only the key-down, and a real Cmd/Ctrl+V may release its
172
168
  // modifier before V. Blur retires either incomplete gesture so no
@@ -538,12 +534,11 @@ pub const RuntimeView = struct {
538
534
  /// one is still held, on hosts that emit input-method text before
539
535
  /// its key_down) flows instead of being eaten by a stale latch.
540
536
  canvas_widget_claimed_key_grace: CanvasWidgetClaimedKeyGrace = .none,
541
- /// A physical Tab whose first key-down moved focus INTO a live
542
- /// terminal. Its auto-repeats and eventual release still belong to
543
- /// focus traversal, not the newly focused pty; the gpu-input pass
544
- /// suppresses those transitions and clears this on key-up (or view
545
- /// blur through `clearImeGraceOnViewBlur`).
546
- canvas_widget_terminal_focus_entry_tab_held: bool = false,
537
+ /// A physical Tab whose first key-down moved focus INTO a Tab-owning
538
+ /// editor (live terminal or editable code). Its auto-repeats and
539
+ /// eventual release still belong to focus traversal, not input for
540
+ /// the newly focused target.
541
+ canvas_widget_tab_input_focus_entry_held: bool = false,
547
542
  /// A Cmd/Ctrl+V key-down the clipboard pass converted into terminal
548
543
  /// paste input. Its physical V release belongs to that paste even if
549
544
  /// the modifier came up first; the raw gpu-input pass consumes it
@@ -706,6 +701,11 @@ pub const RuntimeView = struct {
706
701
  canvas_widget_click_count: u8 = 0,
707
702
  canvas_widget_click_timestamp_ns: u64 = 0,
708
703
  canvas_widget_click_point: geometry.PointF = .{},
704
+ /// A chain belongs to one physical pointer and one resolved press/text
705
+ /// target. Nearby controls must never donate the first click of another
706
+ /// control's double-click gesture.
707
+ canvas_widget_click_pointer_id: u64 = 0,
708
+ canvas_widget_click_target_id: canvas.ObjectId = 0,
709
709
  /// The anchor RUN of an in-flight multi-click drag: the word (or
710
710
  /// line) selected by the initiating double (triple) click. Drag
711
711
  /// extension unions the run under the pointer with this range, so
@@ -724,7 +724,11 @@ pub const RuntimeView = struct {
724
724
  canvas_widget_drag_regions: [canvas_limits.max_canvas_widget_window_drag_regions_per_view]platform.WindowDragRegion = undefined,
725
725
  canvas_widget_drag_region_count: usize = 0,
726
726
  canvas_widget_drag_regions_pushed: bool = false,
727
- widget_text_bytes: [max_canvas_widget_text_bytes_per_view]u8 = undefined,
727
+ widget_text_inline_bytes: [canvas_limits.max_canvas_widget_inline_text_bytes_per_view]u8 = undefined,
728
+ /// Points at `widget_text_inline_bytes` for ordinary views and upgrades to
729
+ /// heap-owned large-file capacity only when a retained layout needs it.
730
+ widget_text_bytes: []u8 = &.{},
731
+ widget_text_bytes_heap_owned: bool = false,
728
732
  widget_text_len: usize = 0,
729
733
  widget_span_entries: [canvas_limits.max_canvas_widget_spans_per_view]canvas.TextSpan = undefined,
730
734
  widget_span_len: usize = 0,
@@ -763,7 +767,9 @@ pub const RuntimeView = struct {
763
767
  /// snapshot.
764
768
  canvas_widget_text_history_entries: [max_canvas_widget_text_history_entries_per_view]view_widget_text.CanvasWidgetTextHistoryEntry = undefined,
765
769
  canvas_widget_text_history_entry_count: usize = 0,
766
- canvas_widget_text_history_bytes: [max_canvas_widget_text_history_bytes_per_view]u8 = undefined,
770
+ canvas_widget_text_history_inline_bytes: [canvas_limits.max_canvas_widget_inline_text_history_bytes_per_view]u8 = undefined,
771
+ canvas_widget_text_history_bytes: []u8 = &.{},
772
+ canvas_widget_text_history_bytes_heap_owned: bool = false,
767
773
  canvas_widget_text_history_byte_count: usize = 0,
768
774
  canvas_widget_text_history_next_serial: u64 = 1,
769
775
  /// Native textarea Up/Down retains its painted x coordinate while a
@@ -781,6 +787,7 @@ pub const RuntimeView = struct {
781
787
  const CanvasWidgetTextMethods = view_widget_text.RuntimeViewCanvasWidgetText(RuntimeView);
782
788
  pub const applyCanvasWidgetTextEdit = CanvasWidgetTextMethods.applyCanvasWidgetTextEdit;
783
789
  pub const applyCanvasWidgetTextEditWithoutHistory = CanvasWidgetTextMethods.applyCanvasWidgetTextEditWithoutHistory;
790
+ pub const canvasWidgetTextEditNeedsLargeStorage = CanvasWidgetTextMethods.canvasWidgetTextEditNeedsLargeStorage;
784
791
  pub const canvasWidgetKeyboardTextEdit = CanvasWidgetTextMethods.canvasWidgetKeyboardTextEdit;
785
792
  pub const canvasWidgetTextHistoryShortcut = CanvasWidgetTextMethods.canvasWidgetTextHistoryShortcut;
786
793
  pub const canvasWidgetTextHistoryAvailability = CanvasWidgetTextMethods.canvasWidgetTextHistoryAvailability;
@@ -1199,7 +1206,21 @@ pub const RuntimeView = struct {
1199
1206
  }
1200
1207
 
1201
1208
  pub fn copyRuntimeStateFrom(self: *RuntimeView, source: *const RuntimeView, scratch: *canvas_widget_runtime.CanvasWidgetCopyScratch) void {
1209
+ const widget_text_bytes = self.widget_text_bytes;
1210
+ const widget_text_bytes_heap_owned = self.widget_text_bytes_heap_owned;
1211
+ const text_history_bytes = self.canvas_widget_text_history_bytes;
1212
+ const text_history_bytes_heap_owned = self.canvas_widget_text_history_bytes_heap_owned;
1202
1213
  self.* = source.*;
1214
+ self.widget_text_bytes = widget_text_bytes;
1215
+ self.widget_text_bytes_heap_owned = widget_text_bytes_heap_owned;
1216
+ self.canvas_widget_text_history_bytes = text_history_bytes;
1217
+ self.canvas_widget_text_history_bytes_heap_owned = text_history_bytes_heap_owned;
1218
+ if (self.canvas_widget_text_history_bytes.ptr != source.canvas_widget_text_history_bytes.ptr) {
1219
+ @memcpy(
1220
+ self.canvas_widget_text_history_bytes[0..source.canvas_widget_text_history_byte_count],
1221
+ source.canvas_widget_text_history_bytes[0..source.canvas_widget_text_history_byte_count],
1222
+ );
1223
+ }
1203
1224
  self.label = copyInto(&self.label_storage, source.label) catch unreachable;
1204
1225
  self.parent = if (source.parent) |parent| copyInto(&self.parent_storage, parent) catch unreachable else null;
1205
1226
  self.role = copyInto(&self.role_storage, source.role) catch unreachable;
@@ -1213,4 +1234,21 @@ pub const RuntimeView = struct {
1213
1234
  self.widget_revision = source.widget_revision;
1214
1235
  @memcpy(self.widget_scroll_states[0..source.widget_layout_node_count], source.widget_scroll_states[0..source.widget_layout_node_count]);
1215
1236
  }
1237
+
1238
+ pub fn ensureLargeCanvasWidgetTextStorage(self: *RuntimeView, allocator: std.mem.Allocator) !void {
1239
+ if (self.widget_text_bytes_heap_owned) return;
1240
+ const text_bytes = try allocator.alloc(u8, canvas_limits.max_canvas_widget_text_bytes_per_view);
1241
+ errdefer allocator.free(text_bytes);
1242
+ const history_bytes = try allocator.alloc(u8, canvas_limits.max_canvas_widget_text_history_bytes_per_view);
1243
+ errdefer allocator.free(history_bytes);
1244
+ @memcpy(text_bytes[0..self.widget_text_len], self.widget_text_bytes[0..self.widget_text_len]);
1245
+ @memcpy(
1246
+ history_bytes[0..self.canvas_widget_text_history_byte_count],
1247
+ self.canvas_widget_text_history_bytes[0..self.canvas_widget_text_history_byte_count],
1248
+ );
1249
+ self.widget_text_bytes = text_bytes;
1250
+ self.widget_text_bytes_heap_owned = true;
1251
+ self.canvas_widget_text_history_bytes = history_bytes;
1252
+ self.canvas_widget_text_history_bytes_heap_owned = true;
1253
+ }
1216
1254
  };