@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.
- package/build.zig +65 -91
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/text.ts +25 -14
- package/packages/core/src/checker.ts +39 -0
- package/packages/core/src/emitter.ts +125 -1
- package/skill-data/native-ui/SKILL.md +9 -7
- package/src/platform/macos/appkit_host.m +25 -1
- package/src/platform/macos/cef_host.mm +24 -2
- package/src/platform/macos/root.zig +13 -0
- package/src/primitives/canvas/code.zig +451 -33
- package/src/primitives/canvas/code_tests.zig +855 -5
- package/src/primitives/canvas/events.zig +111 -1
- package/src/primitives/canvas/markdown_tests.zig +17 -18
- package/src/primitives/canvas/root.zig +4 -0
- package/src/primitives/canvas/text.zig +6 -0
- package/src/primitives/canvas/ui.zig +108 -29
- package/src/primitives/canvas/ui_markup.zig +23 -9
- package/src/primitives/canvas/ui_markup_compiled.zig +13 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +12 -0
- package/src/primitives/canvas/ui_markup_contract.zig +8 -1
- package/src/primitives/canvas/ui_markup_view.zig +16 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +71 -5
- package/src/primitives/canvas/ui_schema.zig +13 -0
- package/src/primitives/canvas/ui_schema_tests.zig +9 -7
- package/src/primitives/canvas/ui_tests.zig +26 -0
- package/src/primitives/canvas/widget_invalidation.zig +1 -0
- package/src/primitives/canvas/widget_metrics.zig +10 -5
- package/src/primitives/canvas/widget_render.zig +660 -39
- package/src/primitives/canvas/widget_render_controls.zig +4 -4
- package/src/primitives/canvas/widget_runtime.zig +2 -0
- package/src/primitives/canvas/widget_text_input.zig +165 -8
- package/src/primitives/canvas/widget_tree.zig +6 -5
- package/src/primitives/canvas/widgets.zig +25 -0
- package/src/runtime/canvas_budget_edge_tests.zig +3 -2
- package/src/runtime/canvas_limits.zig +13 -6
- package/src/runtime/canvas_widget_clipboard_tests.zig +7 -4
- package/src/runtime/canvas_widget_context_menu.zig +7 -2
- package/src/runtime/canvas_widget_event_tests.zig +18 -14
- package/src/runtime/canvas_widget_events.zig +51 -20
- package/src/runtime/canvas_widget_runtime.zig +105 -4
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
- package/src/runtime/canvas_widget_state.zig +27 -0
- package/src/runtime/canvas_widget_text_tests.zig +326 -0
- package/src/runtime/core.zig +15 -5
- package/src/runtime/gpu_surface_events.zig +12 -12
- package/src/runtime/view.zig +54 -16
- package/src/runtime/view_widget_scroll.zig +48 -18
- package/src/runtime/view_widget_text.zig +54 -13
- package/src/runtime/window_view_runtime.zig +9 -0
|
@@ -1479,7 +1479,7 @@ fn widgetIconGlyphScale(widget: Widget) f32 {
|
|
|
1479
1479
|
};
|
|
1480
1480
|
}
|
|
1481
1481
|
|
|
1482
|
-
fn emitWidgetTextSelectionRects(
|
|
1482
|
+
pub fn emitWidgetTextSelectionRects(
|
|
1483
1483
|
builder: *Builder,
|
|
1484
1484
|
widget: Widget,
|
|
1485
1485
|
text: DrawText,
|
|
@@ -1513,7 +1513,7 @@ fn emitWidgetTextSelectionRects(
|
|
|
1513
1513
|
/// (re-shaping the selected substring instead would re-kern at the
|
|
1514
1514
|
/// segment boundary and shift the halves apart). Runs after the base
|
|
1515
1515
|
/// text so the recolored glyphs paint over their normal-ink twins.
|
|
1516
|
-
fn emitWidgetTextSelectedGlyphs(
|
|
1516
|
+
pub fn emitWidgetTextSelectedGlyphs(
|
|
1517
1517
|
builder: *Builder,
|
|
1518
1518
|
widget: Widget,
|
|
1519
1519
|
text: DrawText,
|
|
@@ -1550,7 +1550,7 @@ fn textSelectionOverlayCommandId(seed: u64, widget_id: ObjectId, ordinal: usize)
|
|
|
1550
1550
|
return if (value == 0) 1 else value;
|
|
1551
1551
|
}
|
|
1552
1552
|
|
|
1553
|
-
fn emitWidgetTextCompositionLines(
|
|
1553
|
+
pub fn emitWidgetTextCompositionLines(
|
|
1554
1554
|
builder: *Builder,
|
|
1555
1555
|
widget: Widget,
|
|
1556
1556
|
text: DrawText,
|
|
@@ -1587,7 +1587,7 @@ fn widgetTextRangePart(first_part: ObjectId, overflow_first_part: ObjectId, inde
|
|
|
1587
1587
|
return overflow_first_part + @as(ObjectId, @intCast(index - 1));
|
|
1588
1588
|
}
|
|
1589
1589
|
|
|
1590
|
-
fn emitWidgetTextCaret(
|
|
1590
|
+
pub fn emitWidgetTextCaret(
|
|
1591
1591
|
builder: *Builder,
|
|
1592
1592
|
widget: Widget,
|
|
1593
1593
|
text: DrawText,
|
|
@@ -49,6 +49,8 @@ pub const textInputViewportForWidget = widget_text_input.textInputViewportForWid
|
|
|
49
49
|
pub const textInputClearButtonRect = widget_text_input.textInputClearButtonRect;
|
|
50
50
|
pub const textInputClearButtonHitRect = widget_text_input.textInputClearButtonHitRect;
|
|
51
51
|
pub const textInputContentExtentForWidget = widget_text_input.textInputContentExtentForWidget;
|
|
52
|
+
pub const textInputContentWidthForWidget = widget_text_input.textInputContentWidthForWidget;
|
|
53
|
+
pub const cacheTextInputContentWidthForWidget = widget_text_input.cacheTextInputContentWidthForWidget;
|
|
52
54
|
pub const textInputMaxScrollOffsetForWidget = widget_text_input.textInputMaxScrollOffsetForWidget;
|
|
53
55
|
pub const clampedTextInputScrollOffsetForWidget = widget_text_input.clampedTextInputScrollOffsetForWidget;
|
|
54
56
|
pub const textInputMaxHorizontalScrollOffsetForWidget = widget_text_input.textInputMaxHorizontalScrollOffsetForWidget;
|
|
@@ -6,6 +6,7 @@ const token_model = @import("tokens.zig");
|
|
|
6
6
|
const widget_model = @import("widgets.zig");
|
|
7
7
|
const widget_access = @import("widget_access.zig");
|
|
8
8
|
const widget_metrics = @import("widget_metrics.zig");
|
|
9
|
+
const text_measure_cache = @import("text_measure_cache.zig");
|
|
9
10
|
|
|
10
11
|
const FontId = @import("root.zig").FontId;
|
|
11
12
|
const Builder = @import("commands.zig").Builder;
|
|
@@ -85,12 +86,12 @@ pub fn widgetTextInputTextNeedsPresentation(widget: Widget) bool {
|
|
|
85
86
|
/// scroll measures) substitute into. Every entry point re-derives it,
|
|
86
87
|
/// and within one widget's computation repeated derivations write
|
|
87
88
|
/// identical bytes, so the aliasing is harmless. Sized to the runtime's
|
|
88
|
-
/// per-view widget-text budget
|
|
89
|
+
/// per-view widget-text budget. Nothing EMITTED may retain a
|
|
89
90
|
/// slice into it: render emitters persist presented bytes into the
|
|
90
91
|
/// display-list builder via `persistWidgetTextInputPresentedText`, whose
|
|
91
92
|
/// storage lives exactly as long as the emitted commands do.
|
|
92
93
|
const WidgetTextPresentationScratch = struct {
|
|
93
|
-
slot: [
|
|
94
|
+
slot: [text_model.max_widget_text_bytes_per_view]u8,
|
|
94
95
|
};
|
|
95
96
|
const widget_text_presentation_scratch = @import("lazy_tls.zig").LazyTls(WidgetTextPresentationScratch);
|
|
96
97
|
|
|
@@ -113,6 +114,18 @@ fn presentedSingleLineText(text: []const u8) []const u8 {
|
|
|
113
114
|
return scratch.slot[0..text.len];
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
test "single-line presentation rewrites values above the former 64 KiB ceiling" {
|
|
118
|
+
const input = try std.testing.allocator.alloc(u8, 65537);
|
|
119
|
+
defer std.testing.allocator.free(input);
|
|
120
|
+
@memset(input, 'a');
|
|
121
|
+
input[32768] = '\n';
|
|
122
|
+
|
|
123
|
+
const presented = widgetTextInputPresentedText(.{ .kind = .input, .text = input });
|
|
124
|
+
try std.testing.expectEqual(input.len, presented.len);
|
|
125
|
+
try std.testing.expectEqual(@as(u8, ' '), presented[32768]);
|
|
126
|
+
try std.testing.expect(std.mem.indexOfAny(u8, presented, "\r\n") == null);
|
|
127
|
+
}
|
|
128
|
+
|
|
116
129
|
/// Persist presented bytes into the display-list BUILDER so an emitted
|
|
117
130
|
/// command outlives the shared slot (a later widget's presentation
|
|
118
131
|
/// overwrites it) — builder-owned storage, because the builder contract
|
|
@@ -178,12 +191,14 @@ fn widgetTextInputLineHeight(text_size: f32) f32 {
|
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
fn widgetTextInputWrap(widget: Widget, line_height: f32) TextWrap {
|
|
194
|
+
if (widget.code_editor) return if (widget.text_no_wrap) .none else .word;
|
|
181
195
|
if (widget.kind == .textarea) return .word;
|
|
182
196
|
if (widget.kind == .text_field and widget.frame.height >= line_height * 2.25) return .word;
|
|
183
197
|
return .none;
|
|
184
198
|
}
|
|
185
199
|
|
|
186
200
|
fn widgetTextInputVerticalInset(widget: Widget, tokens: DesignTokens, text_size: f32, options: TextLayoutOptions) f32 {
|
|
201
|
+
if (widget.code_editor) return 0;
|
|
187
202
|
if (options.wrap != .none) return widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.sm);
|
|
188
203
|
return @max(0, (widget.frame.height - widgetTextInputLineHeight(text_size)) * 0.5);
|
|
189
204
|
}
|
|
@@ -205,7 +220,8 @@ const text_input_caret_reserve: f32 = 1;
|
|
|
205
220
|
/// unscrolled field always has.
|
|
206
221
|
fn widgetTextInputHorizontalScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
|
|
207
222
|
if (options.wrap != .none) return 0;
|
|
208
|
-
|
|
223
|
+
const offset = if (widget.code_editor) widget.value_x else widget.value;
|
|
224
|
+
return std.math.clamp(offset, 0, widgetTextInputMaxHorizontalScrollOffset(widget, tokens, text_size, text_inset, options));
|
|
209
225
|
}
|
|
210
226
|
|
|
211
227
|
fn widgetTextInputMaxHorizontalScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
|
|
@@ -215,11 +231,24 @@ fn widgetTextInputMaxHorizontalScrollOffset(widget: Widget, tokens: DesignTokens
|
|
|
215
231
|
// Measure the PRESENTED bytes — the ones the field lays out and
|
|
216
232
|
// paints — so a value holding a line break scrolls by the same
|
|
217
233
|
// single-line extent it draws.
|
|
218
|
-
const
|
|
234
|
+
const font_id = widgetTextInputFontId(widget, tokens);
|
|
235
|
+
const text_width = if (widget.code_editor)
|
|
236
|
+
if (codeContentWidthCacheCurrent(widget, font_id, text_size))
|
|
237
|
+
widget.code_content_width
|
|
238
|
+
else
|
|
239
|
+
widestLogicalLineWidth(options.measure, font_id, widget.text, text_size)
|
|
240
|
+
else
|
|
241
|
+
measureTextWidthForFont(options.measure, font_id, widgetTextInputPresentedText(widget), text_size);
|
|
219
242
|
return @max(0, text_width + text_input_caret_reserve - viewport.width);
|
|
220
243
|
}
|
|
221
244
|
|
|
222
245
|
pub fn widgetTextInputOrigin(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32, options: TextLayoutOptions) geometry.PointF {
|
|
246
|
+
if (widget.code_editor) {
|
|
247
|
+
return geometry.PointF.init(
|
|
248
|
+
widget.frame.x + inset - widgetTextInputHorizontalScrollOffset(widget, tokens, text_size, inset, options),
|
|
249
|
+
widget.frame.y + text_size - widgetTextInputScrollOffset(widget, tokens, text_size, inset, options),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
223
252
|
if (options.wrap != .none) {
|
|
224
253
|
const scroll_offset = widgetTextInputScrollOffset(widget, tokens, text_size, inset, options);
|
|
225
254
|
return geometry.PointF.init(
|
|
@@ -263,7 +292,20 @@ pub fn textInputContentExtentForWidget(widget: Widget, tokens: DesignTokens) f32
|
|
|
263
292
|
const text_inset = widgetTextInputInset(widget, tokens);
|
|
264
293
|
const options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
|
|
265
294
|
const line_height = widgetTextInputLineHeight(text_size);
|
|
266
|
-
return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, tokens
|
|
295
|
+
return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, widgetTextInputFontId(widget, tokens), text_size, options))) * line_height;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
pub fn textInputContentWidthForWidget(widget: Widget, tokens: DesignTokens) f32 {
|
|
299
|
+
if (!widget_access.widgetTextInputKind(widget.kind)) return 0;
|
|
300
|
+
const text_size = widgetTextInputSize(widget, tokens);
|
|
301
|
+
const inset = widgetTextInputInset(widget, tokens);
|
|
302
|
+
const options = widgetTextInputLayoutOptions(widget, tokens, text_size, inset);
|
|
303
|
+
const viewport = widgetTextInputClipRect(widget, tokens, text_size, inset, options);
|
|
304
|
+
// Content and viewport share the source-text coordinate space. In a
|
|
305
|
+
// numbered editor the outer frame also contains the pinned gutter;
|
|
306
|
+
// counting that frame here while scrolling against `viewport.width`
|
|
307
|
+
// manufactures a gutter-wide range even when the longest line fits.
|
|
308
|
+
return viewport.width + widgetTextInputMaxHorizontalScrollOffset(widget, tokens, text_size, inset, options);
|
|
267
309
|
}
|
|
268
310
|
|
|
269
311
|
pub fn textInputMaxScrollOffsetForWidget(widget: Widget, tokens: DesignTokens) f32 {
|
|
@@ -323,7 +365,17 @@ pub fn textInputCaretVisibleScrollOffsetForWidget(widget: Widget, tokens: Design
|
|
|
323
365
|
// selection rects measure with — the PRESENTED bytes (byte offsets
|
|
324
366
|
// are interchangeable: the presentation substitutes 1:1).
|
|
325
367
|
const caret_offset = snapTextOffset(widget.text, selection.focus);
|
|
326
|
-
const
|
|
368
|
+
const caret_line_start = if (widget.code_editor)
|
|
369
|
+
(std.mem.lastIndexOfScalar(u8, widget.text[0..caret_offset], '\n') orelse 0) +
|
|
370
|
+
@as(usize, @intFromBool(std.mem.lastIndexOfScalar(u8, widget.text[0..caret_offset], '\n') != null))
|
|
371
|
+
else
|
|
372
|
+
0;
|
|
373
|
+
const caret_x = measureTextWidthForFont(
|
|
374
|
+
options.measure,
|
|
375
|
+
widgetTextInputFontId(widget, tokens),
|
|
376
|
+
widgetTextInputPresentedText(widget)[caret_line_start..caret_offset],
|
|
377
|
+
text_size,
|
|
378
|
+
);
|
|
327
379
|
const margin = textInputCaretVisibleMargin(viewport.width);
|
|
328
380
|
var next = clamped;
|
|
329
381
|
const scrolled_in = caret_x + text_input_caret_reserve + margin - viewport.width;
|
|
@@ -358,7 +410,7 @@ pub fn widgetTextInputClipsText(widget: Widget, tokens: DesignTokens, text_size:
|
|
|
358
410
|
|
|
359
411
|
fn widgetTextInputMaxScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
|
|
360
412
|
const viewport = widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
|
|
361
|
-
return @max(0, textInputContentExtentForWidgetWithOptions(widget, tokens
|
|
413
|
+
return @max(0, textInputContentExtentForWidgetWithOptions(widget, widgetTextInputFontId(widget, tokens), text_size, options) - viewport.height);
|
|
362
414
|
}
|
|
363
415
|
|
|
364
416
|
fn textInputContentExtentForWidgetWithOptions(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) f32 {
|
|
@@ -397,7 +449,7 @@ pub fn widgetTextInputDrawText(
|
|
|
397
449
|
options: TextLayoutOptions,
|
|
398
450
|
) DrawText {
|
|
399
451
|
return .{
|
|
400
|
-
.font_id = tokens
|
|
452
|
+
.font_id = widgetTextInputFontId(widget, tokens),
|
|
401
453
|
.size = text_size,
|
|
402
454
|
.origin = pixelSnapTextPoint(tokens, origin),
|
|
403
455
|
.color = color,
|
|
@@ -412,6 +464,7 @@ pub fn widgetTextInputDrawText(
|
|
|
412
464
|
}
|
|
413
465
|
|
|
414
466
|
pub fn widgetTextInputInset(widget: Widget, tokens: DesignTokens) f32 {
|
|
467
|
+
if (widget.code_editor) return widget_metrics.widgetCodeLineNumberGutterWidth(widget, tokens);
|
|
415
468
|
const text_size = widgetTextInputSize(widget, tokens);
|
|
416
469
|
return switch (widget.kind) {
|
|
417
470
|
.search_field, .combobox => widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.md) + @max(widget_metrics.widgetSizedDensityValue(widget, tokens, 8), text_size - 2) + widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.sm),
|
|
@@ -419,7 +472,111 @@ pub fn widgetTextInputInset(widget: Widget, tokens: DesignTokens) f32 {
|
|
|
419
472
|
};
|
|
420
473
|
}
|
|
421
474
|
|
|
475
|
+
fn widgetTextInputFontId(widget: Widget, tokens: DesignTokens) FontId {
|
|
476
|
+
return if (widget.code_editor) tokens.typography.mono_font_id else tokens.typography.font_id;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32) bool {
|
|
480
|
+
return widget.code_content_width_generation == text_measure_cache.textMeasureGeneration() and
|
|
481
|
+
widget.code_content_width_font_id == font_id and
|
|
482
|
+
widget.code_content_width_size_bits == @as(u32, @bitCast(text_size)) and
|
|
483
|
+
widget.code_content_width >= 0 and
|
|
484
|
+
std.math.isFinite(widget.code_content_width);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/// Populate the retained longest-line width once per source/font generation.
|
|
488
|
+
/// Runtime reconciliation carries this cache across unchanged app rebuilds;
|
|
489
|
+
/// edits invalidate it before caret scrolling recomputes the new document.
|
|
490
|
+
pub fn cacheTextInputContentWidthForWidget(widget: *Widget, tokens: DesignTokens) void {
|
|
491
|
+
if (widget.kind != .textarea or !widget.code_editor or !widget.text_no_wrap) return;
|
|
492
|
+
const text_size = widgetTextInputSize(widget.*, tokens);
|
|
493
|
+
const font_id = widgetTextInputFontId(widget.*, tokens);
|
|
494
|
+
if (codeContentWidthCacheCurrent(widget.*, font_id, text_size)) return;
|
|
495
|
+
widget.code_content_width = widestLogicalLineWidth(tokens.text_measure, font_id, widget.text, text_size);
|
|
496
|
+
widget.code_content_width_generation = text_measure_cache.textMeasureGeneration();
|
|
497
|
+
widget.code_content_width_font_id = font_id;
|
|
498
|
+
widget.code_content_width_size_bits = @bitCast(text_size);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
fn widestLogicalLineWidth(
|
|
502
|
+
measure: ?*const text_model.TextMeasureProvider,
|
|
503
|
+
font_id: FontId,
|
|
504
|
+
text: []const u8,
|
|
505
|
+
text_size: f32,
|
|
506
|
+
) f32 {
|
|
507
|
+
if (measure) |provider| {
|
|
508
|
+
if (widestLogicalLineWidthBatched(provider, font_id, text, text_size)) |width| return width;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
var widest: f32 = 0;
|
|
512
|
+
var start: usize = 0;
|
|
513
|
+
while (start <= text.len) {
|
|
514
|
+
const end = std.mem.indexOfScalarPos(u8, text, start, '\n') orelse text.len;
|
|
515
|
+
widest = @max(widest, measureTextWidthForFont(measure, font_id, text[start..end], text_size));
|
|
516
|
+
if (end == text.len) break;
|
|
517
|
+
start = end + 1;
|
|
518
|
+
}
|
|
519
|
+
return widest;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/// Measure many ordinary source lines in one provider round-trip. Chunks end
|
|
523
|
+
/// at a newline so shaping never crosses a logical-line boundary. A single
|
|
524
|
+
/// extraordinary line above the batched scratch bound takes one width call;
|
|
525
|
+
/// the common 10,000-line document takes only a handful of batched calls.
|
|
526
|
+
fn widestLogicalLineWidthBatched(
|
|
527
|
+
provider: *const text_model.TextMeasureProvider,
|
|
528
|
+
font_id: FontId,
|
|
529
|
+
text: []const u8,
|
|
530
|
+
text_size: f32,
|
|
531
|
+
) ?f32 {
|
|
532
|
+
if (provider.measure_advances_fn == null) return null;
|
|
533
|
+
if (text.len == 0) return 0;
|
|
534
|
+
|
|
535
|
+
var widest: f32 = 0;
|
|
536
|
+
var chunk_start: usize = 0;
|
|
537
|
+
while (chunk_start < text.len) {
|
|
538
|
+
const limit_end = @min(
|
|
539
|
+
text.len,
|
|
540
|
+
chunk_start +| text_measure_cache.max_batched_advance_run_bytes,
|
|
541
|
+
);
|
|
542
|
+
var chunk_end = limit_end;
|
|
543
|
+
if (limit_end < text.len) {
|
|
544
|
+
const bounded = text[chunk_start..limit_end];
|
|
545
|
+
if (std.mem.lastIndexOfScalar(u8, bounded, '\n')) |newline| {
|
|
546
|
+
chunk_end = chunk_start + newline + 1;
|
|
547
|
+
} else {
|
|
548
|
+
const line_end = std.mem.indexOfScalarPos(u8, text, chunk_start, '\n') orelse text.len;
|
|
549
|
+
widest = @max(
|
|
550
|
+
widest,
|
|
551
|
+
measureTextWidthForFont(provider, font_id, text[chunk_start..line_end], text_size),
|
|
552
|
+
);
|
|
553
|
+
chunk_start = if (line_end < text.len) line_end + 1 else line_end;
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const chunk = text[chunk_start..chunk_end];
|
|
559
|
+
const advances = text_measure_cache.textRunAdvances(provider, font_id, text_size, chunk) orelse return null;
|
|
560
|
+
var line_start: usize = 0;
|
|
561
|
+
for (chunk, 0..) |byte, index| {
|
|
562
|
+
if (byte != '\n') continue;
|
|
563
|
+
widest = @max(widest, text_measure_cache.advanceSliceWidth(advances, line_start, index));
|
|
564
|
+
line_start = index + 1;
|
|
565
|
+
}
|
|
566
|
+
if (line_start < chunk.len) {
|
|
567
|
+
widest = @max(widest, text_measure_cache.advanceSliceWidth(advances, line_start, chunk.len));
|
|
568
|
+
}
|
|
569
|
+
chunk_start = chunk_end;
|
|
570
|
+
}
|
|
571
|
+
return widest;
|
|
572
|
+
}
|
|
573
|
+
|
|
422
574
|
fn widgetTextInputTrailingInset(widget: Widget, text_size: f32, inset: f32) f32 {
|
|
575
|
+
// A code editor's leading inset is its line-number gutter, not symmetric
|
|
576
|
+
// field padding. Its source viewport runs all the way to the trailing
|
|
577
|
+
// edge; mirroring the gutter here invents horizontal overflow for lines
|
|
578
|
+
// that visibly fit beside the numbers.
|
|
579
|
+
if (widget.code_editor) return 0;
|
|
423
580
|
if (widget.kind == .combobox) return inset + @max(8, text_size - 4);
|
|
424
581
|
// A search field holding text reserves the trailing slot for the
|
|
425
582
|
// built-in clear affordance so the text never runs under the x.
|
|
@@ -120,14 +120,15 @@ pub fn widgetVirtualRuntimeScrolled(widget: Widget) bool {
|
|
|
120
120
|
/// their axis through it, and the scrollbar/driver emit only the axes
|
|
121
121
|
/// it grants. Vertical: every scrollable kind (scroll views unless
|
|
122
122
|
/// declared `horizontal`, textareas, the virtualized containers).
|
|
123
|
-
/// Horizontal:
|
|
124
|
-
/// `
|
|
125
|
-
/// (windowed ranges price rows, not columns), so a
|
|
126
|
-
/// never grants the horizontal axis.
|
|
123
|
+
/// Horizontal: a non-virtualized `.scroll_view` declared `horizontal` or
|
|
124
|
+
/// `both`, plus an editable no-wrap code textarea. Virtualization is
|
|
125
|
+
/// vertical machinery (windowed ranges price rows, not columns), so a
|
|
126
|
+
/// virtualized region never grants the horizontal axis.
|
|
127
127
|
pub fn widgetScrollsAxis(widget: Widget, axis: token_model.ScrollAxis) bool {
|
|
128
128
|
return switch (axis) {
|
|
129
129
|
.vertical => widget.kind != .scroll_view or widget.scroll_axes.scrollsVertically() or widget.layout.virtualized,
|
|
130
|
-
.horizontal => widget.kind == .scroll_view and widget.scroll_axes.scrollsHorizontally() and !widget.layout.virtualized
|
|
130
|
+
.horizontal => (widget.kind == .scroll_view and widget.scroll_axes.scrollsHorizontally() and !widget.layout.virtualized) or
|
|
131
|
+
(widget.kind == .textarea and widget.code_editor and widget.text_no_wrap),
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
134
|
|
|
@@ -3,6 +3,7 @@ const geometry = @import("geometry");
|
|
|
3
3
|
const canvas = @import("root.zig");
|
|
4
4
|
const text_model = @import("text.zig");
|
|
5
5
|
const text_spans_model = @import("text_spans.zig");
|
|
6
|
+
const code_model = @import("code.zig");
|
|
6
7
|
const token_model = @import("tokens.zig");
|
|
7
8
|
const chart_model = @import("chart.zig");
|
|
8
9
|
const terminal_grid_model = @import("terminal_grid.zig");
|
|
@@ -870,6 +871,30 @@ pub const Widget = struct {
|
|
|
870
871
|
/// Stamped only by `Ui.code`; there is no generic builder/markup
|
|
871
872
|
/// channel for turning arbitrary paragraphs into numbered code.
|
|
872
873
|
code_line_number_digits: u8 = 0,
|
|
874
|
+
/// Optional one-based logical depth for a flat sequence of tree rows.
|
|
875
|
+
/// Zero keeps the structural nesting contract. A nonzero value lets a
|
|
876
|
+
/// `<for>` render visible rows as siblings while Left/Right still find
|
|
877
|
+
/// the logical parent and first child from their declared levels.
|
|
878
|
+
tree_level: u16 = 0,
|
|
879
|
+
/// Internal marker for an editable `Ui.code` surface. The widget keeps
|
|
880
|
+
/// the `.textarea` kind so the existing editor, IME, clipboard, undo,
|
|
881
|
+
/// selection, and accessibility paths all apply; this bit only swaps
|
|
882
|
+
/// the textarea's visual/geometry policy to bare monospace highlighted
|
|
883
|
+
/// code (no control fill, border, radius, focus ring, or inset).
|
|
884
|
+
code_editor: bool = false,
|
|
885
|
+
/// Syntax grammar for an editable `Ui.code` surface. Editable code
|
|
886
|
+
/// retains one plain source span and tokenizes only visible logical
|
|
887
|
+
/// lines during paint, so large documents do not consume the view's
|
|
888
|
+
/// bounded span pool on offscreen syntax runs.
|
|
889
|
+
code_language: code_model.Language = .plain,
|
|
890
|
+
/// Runtime-owned longest-line measurement for an editable no-wrap code
|
|
891
|
+
/// surface. The signature keeps the value honest across font/appearance
|
|
892
|
+
/// changes; source edits invalidate it before caret and scroll geometry
|
|
893
|
+
/// read it. These fields are renderer state, not builder options.
|
|
894
|
+
code_content_width: f32 = 0,
|
|
895
|
+
code_content_width_generation: u64 = 0,
|
|
896
|
+
code_content_width_font_id: u64 = 0,
|
|
897
|
+
code_content_width_size_bits: u32 = 0,
|
|
873
898
|
/// Nonzero on bounded paragraph chunks that together present one
|
|
874
899
|
/// selectable source-code document. The group id is the structural id
|
|
875
900
|
/// of their internal parent; offsets order each chunk's exact source
|
|
@@ -67,8 +67,9 @@ fn stressUpdate(model: *StressModel, msg: StressMsg) void {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// Static payload storage: tests are single-threaded and the view only
|
|
70
|
-
// reads these.
|
|
71
|
-
|
|
70
|
+
// reads these. Size it from the live retained-text edge so raising that
|
|
71
|
+
// budget cannot make this test fixture fail before the runtime does.
|
|
72
|
+
var text_payload: [canvas_limits.max_canvas_widget_text_bytes_per_view]u8 = undefined;
|
|
72
73
|
var chart_values: [256]f32 = undefined;
|
|
73
74
|
var chart_low: [256]f32 = undefined;
|
|
74
75
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const canvas = @import("canvas");
|
|
2
|
+
|
|
1
3
|
// Per-view canvas budgets. Fixed, documented, loud: capacities are compile
|
|
2
4
|
// time constants sized for a dense desktop view, overflow errors name the
|
|
3
5
|
// budget, and the automation snapshot reports headroom (widget_nodes=N/MAX).
|
|
@@ -169,12 +171,16 @@ pub const max_registered_canvas_font_bytes: usize = 24 * 1024 * 1024;
|
|
|
169
171
|
// lockstep.
|
|
170
172
|
pub const max_canvas_widget_nodes_per_view: usize = 1024;
|
|
171
173
|
pub const max_canvas_widget_semantics_per_view: usize = 1024;
|
|
172
|
-
// Raised from 2048 with the inline-span/markdown work
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
pub const max_canvas_widget_text_bytes_per_view: usize =
|
|
174
|
+
// Raised from 2048 with the inline-span/markdown work, then from 64 KiB for
|
|
175
|
+
// editable code surfaces: a simple editor must retain a practical source
|
|
176
|
+
// file (roughly 10k ordinary code lines) plus the surrounding view chrome.
|
|
177
|
+
// Syntax paint remains viewport-bounded, so this larger SOURCE budget does
|
|
178
|
+
// not enlarge the display list or retained span pools.
|
|
179
|
+
pub const max_canvas_widget_text_bytes_per_view: usize = canvas.max_widget_text_bytes_per_view;
|
|
180
|
+
/// Ordinary views retain the historical 64 KiB pools inline. A view upgrades
|
|
181
|
+
/// to the practical source-file ceiling above only when its adopted layout
|
|
182
|
+
/// actually needs it, so empty/ordinary view creation remains allocation-free.
|
|
183
|
+
pub const max_canvas_widget_inline_text_bytes_per_view: usize = 64 * 1024;
|
|
178
184
|
pub const max_canvas_widget_source_text_entries_per_view: usize = 256;
|
|
179
185
|
/// Retained editor undo/redo is delta-based: changed bytes share this
|
|
180
186
|
/// per-view pool and metadata stays bounded independently. Matching the
|
|
@@ -182,6 +188,7 @@ pub const max_canvas_widget_source_text_entries_per_view: usize = 256;
|
|
|
182
188
|
/// be undone; an unusually large whole-document replacement whose removed
|
|
183
189
|
/// plus inserted bytes exceed the pool simply starts a fresh history.
|
|
184
190
|
pub const max_canvas_widget_text_history_bytes_per_view: usize = max_canvas_widget_text_bytes_per_view;
|
|
191
|
+
pub const max_canvas_widget_inline_text_history_bytes_per_view: usize = 64 * 1024;
|
|
185
192
|
pub const max_canvas_widget_text_history_entries_per_view: usize = 128;
|
|
186
193
|
// Inline styled runs retained across all `.text` widgets of a view. Each
|
|
187
194
|
// span is a small struct (style flags + slices into the widget text
|
|
@@ -350,16 +350,19 @@ test "paste clamps to view text capacity and flags truncation loudly" {
|
|
|
350
350
|
const used = harness.runtime.views[0].widget_text_len;
|
|
351
351
|
const available = canvas_limits.max_canvas_widget_text_bytes_per_view - used;
|
|
352
352
|
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
//
|
|
353
|
+
// Fill the view with repeated maximum clipboard payloads. The retained
|
|
354
|
+
// source budget is intentionally larger than one clipboard transfer;
|
|
355
|
+
// only the final paste clamps against the remaining shared storage.
|
|
356
356
|
const big = try std.testing.allocator.alloc(u8, platform.max_clipboard_data_bytes);
|
|
357
357
|
defer std.testing.allocator.free(big);
|
|
358
358
|
@memset(big, 'a');
|
|
359
359
|
try harness.runtime.writeClipboard(big);
|
|
360
360
|
|
|
361
361
|
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 100, 30));
|
|
362
|
-
|
|
362
|
+
const paste_count = std.math.divCeil(usize, available, big.len) catch unreachable;
|
|
363
|
+
for (0..paste_count) |_| {
|
|
364
|
+
try harness.runtime.dispatchPlatformEvent(app, keyInput("v", cmd));
|
|
365
|
+
}
|
|
363
366
|
|
|
364
367
|
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
365
368
|
try std.testing.expectEqual(available, retained.nodes[1].widget.text.len);
|
|
@@ -36,6 +36,11 @@ const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
|
|
|
36
36
|
|
|
37
37
|
const context_menu_log = std.log.scoped(.zero_context_menu);
|
|
38
38
|
|
|
39
|
+
const CanvasWidgetContextMenuTextScratch = struct {
|
|
40
|
+
group_buffer: [canvas_limits.max_canvas_widget_text_bytes_per_view]u8,
|
|
41
|
+
};
|
|
42
|
+
const canvas_widget_context_menu_text_scratch = canvas.lazy_tls.LazyTls(CanvasWidgetContextMenuTextScratch);
|
|
43
|
+
|
|
39
44
|
/// Reserved item ids of the zero-code default menus.
|
|
40
45
|
pub const default_item_cut: u32 = 1;
|
|
41
46
|
pub const default_item_copy: u32 = 2;
|
|
@@ -398,8 +403,8 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
398
403
|
.terminal => try applyDefaultTerminalAction(self, app, index, pending.target_id, event.item_id),
|
|
399
404
|
.static_copy => {
|
|
400
405
|
if (event.item_id != default_item_copy) return;
|
|
401
|
-
|
|
402
|
-
const text = self.views[index].canvasWidgetCopyText(
|
|
406
|
+
const group_buffer = &canvas_widget_context_menu_text_scratch.get().group_buffer;
|
|
407
|
+
const text = self.views[index].canvasWidgetCopyText(group_buffer) orelse return;
|
|
403
408
|
self.writeClipboard(text) catch return;
|
|
404
409
|
},
|
|
405
410
|
}
|
|
@@ -627,7 +627,7 @@ test "only a focused live terminal owns Tab and focus entry suppresses the whole
|
|
|
627
627
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
628
628
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.target_id);
|
|
629
629
|
try std.testing.expect(app_state.focus_moved);
|
|
630
|
-
try std.testing.expect(harness.runtime.views[0].
|
|
630
|
+
try std.testing.expect(harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
|
|
631
631
|
|
|
632
632
|
// Auto-repeat while Tab is held, then its key-up: neither produces
|
|
633
633
|
// another widget event at the terminal.
|
|
@@ -646,7 +646,7 @@ test "only a focused live terminal owns Tab and focus entry suppresses the whole
|
|
|
646
646
|
.modifiers = .{ .shift = true },
|
|
647
647
|
} });
|
|
648
648
|
try std.testing.expectEqual(@as(u32, 3), app_state.keyboard_count);
|
|
649
|
-
try std.testing.expect(!harness.runtime.views[0].
|
|
649
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
|
|
650
650
|
|
|
651
651
|
// The same nonzero binding after session exit is no longer an input
|
|
652
652
|
// owner: its published grid says the session cannot accept input,
|
|
@@ -2407,12 +2407,14 @@ test "a target-less composition stays target-less when a text field takes focus
|
|
|
2407
2407
|
// The composition STARTS target-less (nothing focused): the preedit
|
|
2408
2408
|
// buffers for the surface's own consumer.
|
|
2409
2409
|
harness.runtime.views[0].canvas_widget_focused_id = 0;
|
|
2410
|
-
try harness.runtime.dispatchPlatformEvent(app, .{
|
|
2411
|
-
.
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2410
|
+
try harness.runtime.dispatchPlatformEvent(app, .{
|
|
2411
|
+
.gpu_surface_input = .{
|
|
2412
|
+
.window_id = 1,
|
|
2413
|
+
.label = "canvas",
|
|
2414
|
+
.kind = .ime_set_composition,
|
|
2415
|
+
.text = "\xe3\x81\x8b", // か
|
|
2416
|
+
},
|
|
2417
|
+
});
|
|
2416
2418
|
try std.testing.expectEqual(@as(u32, 0), app_state.committed_count);
|
|
2417
2419
|
|
|
2418
2420
|
// Focus lands on a text field mid-sequence. The empty commit
|
|
@@ -2600,12 +2602,14 @@ test "target-less IME preedit is per-surface and command chords never commit tex
|
|
|
2600
2602
|
harness.runtime.views[1].focused = true;
|
|
2601
2603
|
|
|
2602
2604
|
// Surface A composes; the preedit is provisional — nothing commits.
|
|
2603
|
-
try harness.runtime.dispatchPlatformEvent(app, .{
|
|
2604
|
-
.
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2605
|
+
try harness.runtime.dispatchPlatformEvent(app, .{
|
|
2606
|
+
.gpu_surface_input = .{
|
|
2607
|
+
.window_id = 1,
|
|
2608
|
+
.label = "canvas-a",
|
|
2609
|
+
.kind = .ime_set_composition,
|
|
2610
|
+
.text = "\xe3\x81\x8b", // か
|
|
2611
|
+
},
|
|
2612
|
+
});
|
|
2609
2613
|
try std.testing.expectEqual(@as(u32, 0), app_state.committed_count);
|
|
2610
2614
|
|
|
2611
2615
|
// THE per-surface pin: surface B's empty commit must NOT insert
|