@native-sdk/cli 0.6.3 → 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 +23 -6
- 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 +1008 -0
- package/src/primitives/canvas/code_tests.zig +1912 -0
- package/src/primitives/canvas/events.zig +111 -1
- package/src/primitives/canvas/layout_audit.zig +3 -1
- package/src/primitives/canvas/markdown.zig +13 -11
- package/src/primitives/canvas/markdown_tests.zig +168 -6
- package/src/primitives/canvas/root.zig +8 -2
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text.zig +6 -0
- package/src/primitives/canvas/text_measure_cache.zig +4 -4
- package/src/primitives/canvas/text_span_tests.zig +254 -0
- package/src/primitives/canvas/text_spans.zig +556 -32
- package/src/primitives/canvas/themes/geist.zig +29 -0
- package/src/primitives/canvas/tokens.zig +72 -2
- package/src/primitives/canvas/ui.zig +400 -22
- package/src/primitives/canvas/ui_markup.zig +78 -7
- package/src/primitives/canvas/ui_markup_compiled.zig +89 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +45 -0
- package/src/primitives/canvas/ui_markup_contract.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +89 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +154 -3
- package/src/primitives/canvas/ui_schema.zig +30 -6
- package/src/primitives/canvas/ui_schema_tests.zig +13 -10
- package/src/primitives/canvas/ui_tests.zig +26 -0
- package/src/primitives/canvas/widget_invalidation.zig +4 -0
- package/src/primitives/canvas/widget_layout.zig +57 -8
- package/src/primitives/canvas/widget_layout_tests.zig +35 -0
- package/src/primitives/canvas/widget_metrics.zig +35 -1
- package/src/primitives/canvas/widget_render.zig +1077 -11
- 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_text_select.zig +2 -2
- package/src/primitives/canvas/widget_tree.zig +6 -5
- package/src/primitives/canvas/widgets.zig +38 -0
- package/src/root.zig +1 -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 +137 -4
- package/src/runtime/canvas_widget_context_menu.zig +17 -2
- package/src/runtime/canvas_widget_event_tests.zig +18 -14
- package/src/runtime/canvas_widget_events.zig +58 -21
- package/src/runtime/canvas_widget_runtime.zig +112 -6
- 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 +383 -0
- package/src/runtime/core.zig +15 -5
- package/src/runtime/gpu_surface_events.zig +12 -12
- package/src/runtime/view.zig +61 -19
- package/src/runtime/view_widget_scroll.zig +48 -18
- package/src/runtime/view_widget_text.zig +248 -17
- package/src/runtime/window_view_runtime.zig +9 -0
|
@@ -134,6 +134,104 @@ pub fn widgetKeyboardNewlineTextEditEvent(kind: WidgetKind, event: WidgetKeyboar
|
|
|
134
134
|
return .{ .insert_text = "\n" };
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
/// Editable code owns a plain Tab as indentation input. The file's
|
|
138
|
+
/// leading whitespace votes for tabs versus spaces; space widths 2..8
|
|
139
|
+
/// compete by how many indentation levels they divide cleanly, with the
|
|
140
|
+
/// wider width winning exact ties (4-space files also divide by 2).
|
|
141
|
+
/// Ambiguous or unindented source falls back to two spaces.
|
|
142
|
+
pub fn widgetCodeTabTextEditEvent(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
143
|
+
if (widget.kind != .textarea or !widget.code_editor or widget.state.disabled) return null;
|
|
144
|
+
if (event.phase != .key_down or event.focus_moved or event.text.len != 0) return null;
|
|
145
|
+
if (event.modifiers.shift or event.modifiers.hasNavigationModifier()) return null;
|
|
146
|
+
if (!std.ascii.eqlIgnoreCase(event.key, "tab")) return null;
|
|
147
|
+
return .{ .insert_text = codeIndentationInsertion(widget) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const CodeIndentKind = enum { none, spaces, tabs };
|
|
151
|
+
|
|
152
|
+
fn codeIndentationInsertion(widget: Widget) []const u8 {
|
|
153
|
+
var tab_lines: usize = 0;
|
|
154
|
+
var space_lines: usize = 0;
|
|
155
|
+
var space_width_scores: [9]usize = @splat(0);
|
|
156
|
+
var only_space_indent: ?usize = null;
|
|
157
|
+
|
|
158
|
+
var line_start: usize = 0;
|
|
159
|
+
while (line_start <= widget.text.len) {
|
|
160
|
+
const newline = std.mem.indexOfScalarPos(u8, widget.text, line_start, '\n');
|
|
161
|
+
const line_end = newline orelse widget.text.len;
|
|
162
|
+
const line = widget.text[line_start..line_end];
|
|
163
|
+
var cursor: usize = 0;
|
|
164
|
+
var spaces: usize = 0;
|
|
165
|
+
var tabs: usize = 0;
|
|
166
|
+
while (cursor < line.len) : (cursor += 1) {
|
|
167
|
+
switch (line[cursor]) {
|
|
168
|
+
' ' => spaces += 1,
|
|
169
|
+
'\t' => tabs += 1,
|
|
170
|
+
else => break,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Whitespace-only lines do not state a file convention.
|
|
174
|
+
if (cursor < line.len and cursor > 0) {
|
|
175
|
+
if (tabs > 0) {
|
|
176
|
+
tab_lines += 1;
|
|
177
|
+
} else {
|
|
178
|
+
space_lines += 1;
|
|
179
|
+
only_space_indent = if (space_lines == 1) spaces else null;
|
|
180
|
+
for (2..space_width_scores.len) |width| {
|
|
181
|
+
if (spaces % width == 0) space_width_scores[width] += 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (newline == null) break;
|
|
187
|
+
line_start = line_end + 1;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const selection = widget.text_selection orelse text_model.TextSelection.collapsed(widget.text.len);
|
|
191
|
+
const local_kind = codeIndentKindAt(widget.text, selection.focus);
|
|
192
|
+
const tabs_win = tab_lines > space_lines or
|
|
193
|
+
(tab_lines == space_lines and tab_lines > 0 and local_kind == .tabs);
|
|
194
|
+
if (tabs_win) return "\t";
|
|
195
|
+
|
|
196
|
+
var inferred_width: usize = 2;
|
|
197
|
+
if (space_lines == 1) {
|
|
198
|
+
const width = only_space_indent orelse 0;
|
|
199
|
+
if (width >= 2 and width <= 8) inferred_width = width;
|
|
200
|
+
} else if (space_lines > 1) {
|
|
201
|
+
var best_width: usize = 2;
|
|
202
|
+
var best_score: usize = 0;
|
|
203
|
+
for (2..space_width_scores.len) |width| {
|
|
204
|
+
const score = space_width_scores[width];
|
|
205
|
+
if (score > best_score or (score == best_score and score > 0 and width > best_width)) {
|
|
206
|
+
best_width = width;
|
|
207
|
+
best_score = score;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (best_score * 2 >= space_lines) inferred_width = best_width;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return switch (inferred_width) {
|
|
214
|
+
3 => " ",
|
|
215
|
+
4 => " ",
|
|
216
|
+
5 => " ",
|
|
217
|
+
6 => " ",
|
|
218
|
+
7 => " ",
|
|
219
|
+
8 => " ",
|
|
220
|
+
else => " ",
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
fn codeIndentKindAt(text: []const u8, offset: usize) CodeIndentKind {
|
|
225
|
+
const caret = @min(offset, text.len);
|
|
226
|
+
const line_start = if (std.mem.lastIndexOfScalar(u8, text[0..caret], '\n')) |newline| newline + 1 else 0;
|
|
227
|
+
if (line_start >= text.len) return .none;
|
|
228
|
+
return switch (text[line_start]) {
|
|
229
|
+
'\t' => .tabs,
|
|
230
|
+
' ' => .spaces,
|
|
231
|
+
else => .none,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
137
235
|
/// The single-line text-entry kinds: their value can never hold a line
|
|
138
236
|
/// break (Enter submits instead of editing — see
|
|
139
237
|
/// `widgetKeyboardNewlineTextEditEvent`), so text inserted into them
|
|
@@ -152,7 +250,7 @@ pub fn widgetKindSingleLineTextEntry(kind: WidgetKind) bool {
|
|
|
152
250
|
/// runtime's per-view widget-text budget
|
|
153
251
|
/// (`max_canvas_widget_text_bytes_per_view`), the largest insert the
|
|
154
252
|
/// editor could accept anyway.
|
|
155
|
-
const max_sanitized_text_edit_bytes: usize =
|
|
253
|
+
const max_sanitized_text_edit_bytes: usize = text_model.max_widget_text_bytes_per_view;
|
|
156
254
|
const SanitizedTextEditScratch = struct {
|
|
157
255
|
bytes: [max_sanitized_text_edit_bytes]u8,
|
|
158
256
|
};
|
|
@@ -946,3 +1044,15 @@ test "sanitizedSingleLineTextInputEvent strips composition text and shifts the p
|
|
|
946
1044
|
const multi = sanitizedSingleLineTextInputEvent(.textarea, .{ .set_composition = .{ .text = "a\nb" } }).?;
|
|
947
1045
|
try testing.expectEqualStrings("a\nb", multi.set_composition.text);
|
|
948
1046
|
}
|
|
1047
|
+
|
|
1048
|
+
test "sanitizedSingleLineTextInputEvent sanitizes inserts above the former 64 KiB ceiling" {
|
|
1049
|
+
const testing = std.testing;
|
|
1050
|
+
const input = try testing.allocator.alloc(u8, 65537);
|
|
1051
|
+
defer testing.allocator.free(input);
|
|
1052
|
+
@memset(input, 'a');
|
|
1053
|
+
input[32768] = '\n';
|
|
1054
|
+
|
|
1055
|
+
const sanitized = sanitizedSingleLineTextInputEvent(.text_field, .{ .insert_text = input }).?;
|
|
1056
|
+
try testing.expectEqual(@as(usize, input.len - 1), sanitized.insert_text.len);
|
|
1057
|
+
try testing.expect(std.mem.indexOfAny(u8, sanitized.insert_text, "\r\n") == null);
|
|
1058
|
+
}
|
|
@@ -244,7 +244,9 @@ fn auditNodeTextOverflow(layout: WidgetLayoutTree, node_index: usize, tokens: De
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
fn auditSpanParagraphOverflow(widget: Widget, frame: geometry.RectF, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
|
|
247
|
-
|
|
247
|
+
var framed_widget = widget;
|
|
248
|
+
framed_widget.frame = frame;
|
|
249
|
+
const content = widget_metrics.widgetTextSpanContentFrame(framed_widget, tokens).normalized();
|
|
248
250
|
var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
|
|
249
251
|
const span_layout = text_spans_model.layoutTextSpans(
|
|
250
252
|
widget.spans,
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
//!
|
|
11
11
|
//! Supported blocks: `#`/`##`/`###` headings (deeper levels clamp to h3),
|
|
12
12
|
//! paragraphs, bullet/ordered/task lists (nesting up to
|
|
13
|
-
//! `max_markdown_list_depth` by two-space indent), fenced code blocks
|
|
13
|
+
//! `max_markdown_list_depth` by two-space indent), fenced code blocks
|
|
14
|
+
//! (source indentation preserved and language-tagged fences highlighted),
|
|
14
15
|
//! `>` blockquotes, horizontal rules, GFM pipe tables (header row +
|
|
15
16
|
//! delimiter row + body rows onto `table`/`data_row`/`data_cell` widgets;
|
|
16
17
|
//! `:---`/`:--:`/`---:` delimiter cells set per-column start/center/end
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
//! that exceed a capacity truncate deterministically.
|
|
58
59
|
|
|
59
60
|
const std = @import("std");
|
|
61
|
+
const code_model = @import("code.zig");
|
|
60
62
|
const geometry = @import("geometry");
|
|
61
63
|
const canvas = @import("root.zig");
|
|
62
64
|
const text_spans = @import("text_spans.zig");
|
|
@@ -291,7 +293,8 @@ pub fn Markdown(comptime Msg: type) type {
|
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
fn parseCodeFence(self: *Builder, lines: *LineIterator) ?Node {
|
|
294
|
-
|
|
296
|
+
const opening = lines.next() orelse return null;
|
|
297
|
+
const language = code_model.languageFromFence(opening);
|
|
295
298
|
const start = lines.index;
|
|
296
299
|
var end = start;
|
|
297
300
|
while (lines.next()) |line| {
|
|
@@ -299,13 +302,7 @@ pub fn Markdown(comptime Msg: type) type {
|
|
|
299
302
|
end = lines.index;
|
|
300
303
|
}
|
|
301
304
|
const code = std.mem.trimEnd(u8, lines.source[start..@min(end, lines.source.len)], "\n");
|
|
302
|
-
|
|
303
|
-
return self.ui.el(.panel, .{
|
|
304
|
-
.padding = 12,
|
|
305
|
-
.style_tokens = .{ .background = .surface_subtle },
|
|
306
|
-
}, .{
|
|
307
|
-
self.ui.paragraph(.{}, &code_span),
|
|
308
|
-
});
|
|
305
|
+
return self.ui.code(.{ .language = language }, code);
|
|
309
306
|
}
|
|
310
307
|
|
|
311
308
|
fn parseBlockquote(self: *Builder, lines: *LineIterator) ?Node {
|
|
@@ -365,9 +362,14 @@ pub fn Markdown(comptime Msg: type) type {
|
|
|
365
362
|
.semantics = .{ .label = marker.content },
|
|
366
363
|
}),
|
|
367
364
|
};
|
|
368
|
-
|
|
365
|
+
// The outer row must keep stretch alignment so a wrapped
|
|
366
|
+
// paragraph receives the row's full measured height. A
|
|
367
|
+
// one-child column consumes that stretched marker slot
|
|
368
|
+
// while laying its marker at the slot's leading edge.
|
|
369
|
+
const lead_top = self.ui.column(.{}, .{lead});
|
|
370
|
+
if (depth == 0) return self.ui.row(.{ .gap = 8 }, .{ lead_top, content });
|
|
369
371
|
const indent = self.ui.el(.stack, .{ .width = @as(f32, @floatFromInt(depth)) * 16 }, .{});
|
|
370
|
-
return self.ui.row(.{ .gap = 8 }, .{ indent,
|
|
372
|
+
return self.ui.row(.{ .gap = 8 }, .{ indent, lead_top, content });
|
|
371
373
|
}
|
|
372
374
|
|
|
373
375
|
fn parseDetails(self: *Builder, lines: *LineIterator) ?Node {
|
|
@@ -48,6 +48,42 @@ fn countKind(widget: canvas.Widget, kind: canvas.WidgetKind) usize {
|
|
|
48
48
|
return count;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
fn findKind(widget: canvas.Widget, kind: canvas.WidgetKind) ?canvas.Widget {
|
|
52
|
+
if (widget.kind == kind) return widget;
|
|
53
|
+
for (widget.children) |child| {
|
|
54
|
+
if (findKind(child, kind)) |found| return found;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn appendParagraphText(widget: canvas.Widget, out: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator) !void {
|
|
60
|
+
if (widget.kind == .text and widget.spans.len > 0) {
|
|
61
|
+
try out.appendSlice(allocator, widget.text);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
for (widget.children) |child| try appendParagraphText(child, out, allocator);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fn hasSpan(widget: canvas.Widget, text: []const u8, color: ?canvas.TextSpanColor) bool {
|
|
68
|
+
for (widget.spans) |span| {
|
|
69
|
+
if (std.mem.eql(u8, span.text, text) and span.color == color) return true;
|
|
70
|
+
}
|
|
71
|
+
for (widget.children) |child| {
|
|
72
|
+
if (hasSpan(child, text, color)) return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn allSpansMonospace(widget: canvas.Widget) bool {
|
|
78
|
+
for (widget.spans) |span| {
|
|
79
|
+
if (!span.monospace) return false;
|
|
80
|
+
}
|
|
81
|
+
for (widget.children) |child| {
|
|
82
|
+
if (!allSpansMonospace(child)) return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
51
87
|
fn findParagraphContaining(widget: canvas.Widget, fragment: []const u8) ?canvas.Widget {
|
|
52
88
|
if (widget.kind == .text and widget.spans.len > 0 and std.mem.indexOf(u8, widget.text, fragment) != null) return widget;
|
|
53
89
|
for (widget.children) |child| {
|
|
@@ -72,6 +108,18 @@ fn findKindLabel(widget: canvas.Widget, kind: canvas.WidgetKind, label: []const
|
|
|
72
108
|
return null;
|
|
73
109
|
}
|
|
74
110
|
|
|
111
|
+
fn findRowWithDirectParagraph(widget: canvas.Widget, fragment: []const u8) ?canvas.Widget {
|
|
112
|
+
if (widget.kind == .row) {
|
|
113
|
+
for (widget.children) |child| {
|
|
114
|
+
if (child.kind == .text and child.spans.len > 0 and std.mem.indexOf(u8, child.text, fragment) != null) return widget;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (widget.children) |child| {
|
|
118
|
+
if (findRowWithDirectParagraph(child, fragment)) |found| return found;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
75
123
|
test "markdown maps headings, paragraphs, and inline styles onto spans" {
|
|
76
124
|
var doc = TestDoc.init();
|
|
77
125
|
defer doc.deinit();
|
|
@@ -144,11 +192,103 @@ test "markdown maps lists, task lists, code fences, quotes, and rules" {
|
|
|
144
192
|
try testing.expect(findParagraphContaining(tree.root, "one") != null);
|
|
145
193
|
try testing.expect(findParagraphContaining(tree.root, "quoted wisdom") != null);
|
|
146
194
|
try testing.expectEqual(@as(usize, 2), countKind(tree.root, .separator));
|
|
147
|
-
|
|
148
|
-
//
|
|
149
|
-
|
|
195
|
+
// The row keeps stretch alignment for wrapped paragraph height, while
|
|
196
|
+
// a leading column pins the marker itself to the first-line edge.
|
|
197
|
+
const bullet_row = findRowWithDirectParagraph(tree.root, "first").?;
|
|
198
|
+
const ordered_row = findRowWithDirectParagraph(tree.root, "one").?;
|
|
199
|
+
try testing.expectEqual(canvas.WidgetCrossAlignment.stretch, bullet_row.layout.cross_alignment);
|
|
200
|
+
try testing.expectEqual(canvas.WidgetKind.column, bullet_row.children[0].kind);
|
|
201
|
+
try testing.expectEqualStrings("•", bullet_row.children[0].children[0].text);
|
|
202
|
+
try testing.expectEqual(canvas.WidgetCrossAlignment.stretch, ordered_row.layout.cross_alignment);
|
|
203
|
+
try testing.expectEqual(canvas.WidgetKind.column, ordered_row.children[0].kind);
|
|
204
|
+
try testing.expectEqualStrings("1.", ordered_row.children[0].children[0].text);
|
|
205
|
+
|
|
206
|
+
// Fences use the same deliberately bare code component.
|
|
207
|
+
try testing.expectEqual(@as(usize, 0), countKind(tree.root, .panel));
|
|
150
208
|
const code = findParagraphContaining(tree.root, "const x = 1;").?;
|
|
151
209
|
try testing.expect(code.spans[0].monospace);
|
|
210
|
+
try testing.expectEqual(@as(?canvas.TextSpanColor, .syntax_keyword), code.spans[0].color);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
test "language-tagged code fences highlight tokens and preserve indentation" {
|
|
214
|
+
var doc = TestDoc.init();
|
|
215
|
+
defer doc.deinit();
|
|
216
|
+
const tree = try doc.build(
|
|
217
|
+
\\```zig
|
|
218
|
+
\\pub fn main() void {
|
|
219
|
+
\\ const message = "hello";
|
|
220
|
+
\\ // keep this indentation
|
|
221
|
+
\\ return 42;
|
|
222
|
+
\\}
|
|
223
|
+
\\```
|
|
224
|
+
, .{});
|
|
225
|
+
|
|
226
|
+
const code = findParagraphContaining(tree.root, "pub fn main() void").?;
|
|
227
|
+
var source_text: std.ArrayListUnmanaged(u8) = .empty;
|
|
228
|
+
defer source_text.deinit(testing.allocator);
|
|
229
|
+
try appendParagraphText(code, &source_text, testing.allocator);
|
|
230
|
+
try testing.expectEqualStrings(
|
|
231
|
+
"pub fn main() void {\n const message = \"hello\";\n // keep this indentation\n return 42;\n}",
|
|
232
|
+
source_text.items,
|
|
233
|
+
);
|
|
234
|
+
try testing.expect(allSpansMonospace(code));
|
|
235
|
+
try testing.expect(hasSpan(code, "pub", .syntax_keyword));
|
|
236
|
+
try testing.expect(hasSpan(code, "void", .syntax_literal));
|
|
237
|
+
try testing.expect(hasSpan(code, "\"hello\"", .syntax_literal));
|
|
238
|
+
try testing.expect(hasSpan(code, "// keep this indentation", .syntax_comment));
|
|
239
|
+
try testing.expect(hasSpan(code, "42", .syntax_literal));
|
|
240
|
+
|
|
241
|
+
const indented = findParagraphContaining(code, "const message").?;
|
|
242
|
+
var runs: [text_spans.max_text_span_runs_per_paragraph]text_spans.TextSpanRun = undefined;
|
|
243
|
+
const layout = text_spans.layoutTextSpans(indented.spans, .{ .size = 14, .max_width = 10_000 }, &runs);
|
|
244
|
+
var indented_keyword_x: ?f32 = null;
|
|
245
|
+
for (layout.runs) |run| {
|
|
246
|
+
if (run.line_index == 1 and std.mem.eql(u8, run.text, "const")) indented_keyword_x = run.x;
|
|
247
|
+
}
|
|
248
|
+
// Four source spaces occupy real horizontal advance before `const`.
|
|
249
|
+
try testing.expect(indented_keyword_x != null);
|
|
250
|
+
try testing.expectApproxEqAbs(@as(f32, 4 * 14 * 0.6), indented_keyword_x.?, 0.01);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
test "unrecognized code-fence languages remain plain monospace" {
|
|
254
|
+
var doc = TestDoc.init();
|
|
255
|
+
defer doc.deinit();
|
|
256
|
+
const tree = try doc.build(
|
|
257
|
+
\\```made-up-language
|
|
258
|
+
\\alpha 42
|
|
259
|
+
\\```
|
|
260
|
+
, .{});
|
|
261
|
+
|
|
262
|
+
const code = findParagraphContaining(tree.root, "alpha 42").?;
|
|
263
|
+
try testing.expectEqual(@as(usize, 1), code.spans.len);
|
|
264
|
+
try testing.expect(code.spans[0].monospace);
|
|
265
|
+
try testing.expectEqual(@as(?canvas.TextSpanColor, .syntax_plain), code.spans[0].color);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
test "per-line syntax highlighting does not drop fenced code" {
|
|
269
|
+
const code_source =
|
|
270
|
+
"const a0 = 0;\n" ++
|
|
271
|
+
"const a1 = 1;\n" ++
|
|
272
|
+
"const a2 = 2;\n" ++
|
|
273
|
+
"const a3 = 3;\n" ++
|
|
274
|
+
"const a4 = 4;\n" ++
|
|
275
|
+
"const a5 = 5;\n" ++
|
|
276
|
+
"const a6 = 6;\n" ++
|
|
277
|
+
"const a7 = 7;\n" ++
|
|
278
|
+
"const a8 = 8;\n" ++
|
|
279
|
+
"const a9 = 9;\n" ++
|
|
280
|
+
"const a10 = 10;\n" ++
|
|
281
|
+
"const a11 = 11;";
|
|
282
|
+
const source = "```zig\n" ++ code_source ++ "\n```";
|
|
283
|
+
|
|
284
|
+
var doc = TestDoc.init();
|
|
285
|
+
defer doc.deinit();
|
|
286
|
+
const tree = try doc.build(source, .{});
|
|
287
|
+
var rendered: std.ArrayListUnmanaged(u8) = .empty;
|
|
288
|
+
defer rendered.deinit(testing.allocator);
|
|
289
|
+
try appendParagraphText(tree.root, &rendered, testing.allocator);
|
|
290
|
+
try testing.expectEqualStrings(code_source, rendered.items);
|
|
291
|
+
try testing.expect(hasSpan(tree.root, "const", .syntax_keyword));
|
|
152
292
|
}
|
|
153
293
|
|
|
154
294
|
test "details blocks are caller-controlled collapsibles" {
|
|
@@ -339,7 +479,7 @@ test "the README-shaped fixture renders through the mapper and the reference ren
|
|
|
339
479
|
const cli_link = findRoleLabel(tree.root, .link, "`flg`").?;
|
|
340
480
|
const open_msg = tree.msgForPointer(cli_link.id, .up).?;
|
|
341
481
|
try testing.expectEqualStrings("https://example.com/flg", open_msg.open_url);
|
|
342
|
-
try testing.
|
|
482
|
+
try testing.expectEqual(@as(usize, 0), countKind(tree.root, .panel));
|
|
343
483
|
|
|
344
484
|
// Layout + emit + reference-render the document; the pixel signature is
|
|
345
485
|
// the golden. Estimator-driven and provider-free: deterministic.
|
|
@@ -391,6 +531,12 @@ test "the README-shaped fixture renders through the mapper and the reference ren
|
|
|
391
531
|
const surface = try canvas.ReferenceRenderSurface.init(width, height, pixels);
|
|
392
532
|
try surface.renderPass(frame.renderPass(), canvas.Color.rgb8(255, 255, 255));
|
|
393
533
|
|
|
534
|
+
// Deliberate golden updates can be reviewed as pixels before pinning
|
|
535
|
+
// the new signature.
|
|
536
|
+
if (markdownGoldenDumpRequested()) {
|
|
537
|
+
try dumpMarkdownGoldenPng("/tmp/markdown-shots/readme.png", width, height, pixels);
|
|
538
|
+
}
|
|
539
|
+
|
|
394
540
|
// Golden: byte-identical reference rendering of the README fixture.
|
|
395
541
|
try testing.expectEqual(markdown_document_reference_signature, support.referenceSurfaceSignature(pixels));
|
|
396
542
|
try support.expectVisiblePixel(surface.pixelRgba8(24, 32));
|
|
@@ -402,11 +548,27 @@ test "the README-shaped fixture renders through the mapper and the reference ren
|
|
|
402
548
|
// scales, wrapped bullets and em-dash spacing at the face's real
|
|
403
549
|
// advances, real sans and mono outlines (fixed-pitch runs sit in their
|
|
404
550
|
// 0.6 em cells), GFM tables as borderless cells on hairline row
|
|
405
|
-
// separators, fenced
|
|
551
|
+
// separators, bare fenced code with preserved source indentation and
|
|
552
|
+
// language-token colors, and near-black underlined links.
|
|
406
553
|
// Update deliberately when markdown rendering changes, reviewing the
|
|
407
554
|
// rendered pixels first (see reference_tests.zig conventions).
|
|
408
|
-
const markdown_document_reference_signature: u64 =
|
|
555
|
+
const markdown_document_reference_signature: u64 = 5787917808851547223;
|
|
409
556
|
|
|
557
|
+
fn markdownGoldenDumpRequested() bool {
|
|
558
|
+
if (comptime !@import("builtin").link_libc) return false;
|
|
559
|
+
return std.c.getenv("MARKDOWN_GOLDEN_DUMP") != null;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
fn dumpMarkdownGoldenPng(path: []const u8, width: usize, height: usize, pixels: []const u8) !void {
|
|
563
|
+
const io = testing.io;
|
|
564
|
+
std.Io.Dir.cwd().createDirPath(io, std.fs.path.dirname(path) orelse ".") catch {};
|
|
565
|
+
var file = try std.Io.Dir.cwd().createFile(io, path, .{});
|
|
566
|
+
defer file.close(io);
|
|
567
|
+
var write_buffer: [4096]u8 = undefined;
|
|
568
|
+
var writer = file.writer(io, &write_buffer);
|
|
569
|
+
try canvas.png.writeRgba8(&writer.interface, width, height, pixels);
|
|
570
|
+
try writer.interface.flush();
|
|
571
|
+
}
|
|
410
572
|
|
|
411
573
|
test "bare URLs autolink at word boundaries with trailing punctuation trimmed" {
|
|
412
574
|
var doc = TestDoc.init();
|
|
@@ -204,6 +204,7 @@ pub const TextCaretDirection = text_model.TextCaretDirection;
|
|
|
204
204
|
pub const TextCaretMove = text_model.TextCaretMove;
|
|
205
205
|
pub const TextCompositionUpdate = text_model.TextCompositionUpdate;
|
|
206
206
|
pub const TextInputEvent = text_model.TextInputEvent;
|
|
207
|
+
pub const max_widget_text_bytes_per_view = text_model.max_widget_text_bytes_per_view;
|
|
207
208
|
pub const TextEditState = text_model.TextEditState;
|
|
208
209
|
pub const TextBuffer = text_model.TextBuffer;
|
|
209
210
|
|
|
@@ -357,6 +358,7 @@ pub const ColorContrast = token_model.ColorContrast;
|
|
|
357
358
|
pub const ThemeOptions = token_model.ThemeOptions;
|
|
358
359
|
pub const ThemePack = token_model.ThemePack;
|
|
359
360
|
pub const ColorTokens = token_model.ColorTokens;
|
|
361
|
+
pub const colorTokenValue = token_model.colorTokenValue;
|
|
360
362
|
pub const FontFamily = token_model.FontFamily;
|
|
361
363
|
pub const TypographyTokens = token_model.TypographyTokens;
|
|
362
364
|
pub const SpacingTokens = token_model.SpacingTokens;
|
|
@@ -530,8 +532,9 @@ pub const max_chart_axis_ticks = chart.max_chart_axis_ticks;
|
|
|
530
532
|
pub const chartPointCount = chart.chartPointCount;
|
|
531
533
|
pub const chartHoverIndex = chart.chartHoverIndex;
|
|
532
534
|
|
|
533
|
-
//
|
|
534
|
-
//
|
|
535
|
+
// Shared source-code lexer/presentation model and GitHub-flavored-markdown
|
|
536
|
+
// mapper. Markdown fenced blocks lower through `Ui.code`.
|
|
537
|
+
pub const code = @import("code.zig");
|
|
535
538
|
pub const markdown = @import("markdown.zig");
|
|
536
539
|
|
|
537
540
|
// Deterministic key-lookup scratch shared by the per-frame planners and
|
|
@@ -635,6 +638,7 @@ pub const WidgetInvalidation = event_model.WidgetInvalidation;
|
|
|
635
638
|
pub const WidgetClipboardAction = event_model.WidgetClipboardAction;
|
|
636
639
|
pub const widgetKeyboardClipboardAction = event_model.widgetKeyboardClipboardAction;
|
|
637
640
|
pub const widgetKeyboardNewlineTextEditEvent = event_model.widgetKeyboardNewlineTextEditEvent;
|
|
641
|
+
pub const widgetCodeTabTextEditEvent = event_model.widgetCodeTabTextEditEvent;
|
|
638
642
|
pub const widgetKindSingleLineTextEntry = event_model.widgetKindSingleLineTextEntry;
|
|
639
643
|
pub const sanitizedSingleLineTextInputEvent = event_model.sanitizedSingleLineTextInputEvent;
|
|
640
644
|
pub const widgetKeyboardControlIntent = event_model.widgetKeyboardControlIntent;
|
|
@@ -716,6 +720,8 @@ pub const textInputViewportForWidget = widget_runtime.textInputViewportForWidget
|
|
|
716
720
|
pub const textInputClearButtonRect = widget_runtime.textInputClearButtonRect;
|
|
717
721
|
pub const textInputClearButtonHitRect = widget_runtime.textInputClearButtonHitRect;
|
|
718
722
|
pub const textInputContentExtentForWidget = widget_runtime.textInputContentExtentForWidget;
|
|
723
|
+
pub const textInputContentWidthForWidget = widget_runtime.textInputContentWidthForWidget;
|
|
724
|
+
pub const cacheTextInputContentWidthForWidget = widget_runtime.cacheTextInputContentWidthForWidget;
|
|
719
725
|
pub const textInputMaxScrollOffsetForWidget = widget_runtime.textInputMaxScrollOffsetForWidget;
|
|
720
726
|
pub const clampedTextInputScrollOffsetForWidget = widget_runtime.clampedTextInputScrollOffsetForWidget;
|
|
721
727
|
pub const textInputMaxHorizontalScrollOffsetForWidget = widget_runtime.textInputMaxHorizontalScrollOffsetForWidget;
|
|
@@ -25,6 +25,7 @@ test {
|
|
|
25
25
|
_ = @import("text_metrics_tests.zig");
|
|
26
26
|
_ = @import("text_batch_tests.zig");
|
|
27
27
|
_ = @import("text_span_tests.zig");
|
|
28
|
+
_ = @import("code_tests.zig");
|
|
28
29
|
_ = @import("markdown_tests.zig");
|
|
29
30
|
_ = @import("markdown_hostile_tests.zig");
|
|
30
31
|
_ = @import("layout_audit_tests.zig");
|
|
@@ -2,6 +2,12 @@ const text_atlas = @import("text_atlas.zig");
|
|
|
2
2
|
const text_layout = @import("text_layout.zig");
|
|
3
3
|
const text_interaction = @import("text_interaction.zig");
|
|
4
4
|
|
|
5
|
+
/// Largest retained widget-text pool a view may expose. Text-event
|
|
6
|
+
/// sanitization and defensive single-line presentation share this ceiling
|
|
7
|
+
/// with the runtime so an insert the editor can accept is never too large for
|
|
8
|
+
/// those correctness seams to rewrite.
|
|
9
|
+
pub const max_widget_text_bytes_per_view: usize = 512 * 1024;
|
|
10
|
+
|
|
5
11
|
pub const Glyph = text_atlas.Glyph;
|
|
6
12
|
pub const GlyphAtlasKey = text_atlas.GlyphAtlasKey;
|
|
7
13
|
pub const GlyphAtlasEntry = text_atlas.GlyphAtlasEntry;
|
|
@@ -72,11 +72,11 @@ pub const max_cached_advance_run_bytes: usize = 2048;
|
|
|
72
72
|
/// the peek/fetch split.
|
|
73
73
|
pub const advance_cache_capacity: usize = 256;
|
|
74
74
|
|
|
75
|
-
/// Oversize scratch: one slot covering runs up to the
|
|
76
|
-
/// budget (`canvas_limits.
|
|
77
|
-
/// long still gets ONE batched call per fetch; it just is not retained
|
|
75
|
+
/// Oversize scratch: one slot covering runs up to the canvas-widget source
|
|
76
|
+
/// budget (`canvas_limits.max_canvas_widget_text_bytes_per_view`). A run
|
|
77
|
+
/// this long still gets ONE batched call per fetch; it just is not retained
|
|
78
78
|
/// across other fetches.
|
|
79
|
-
pub const max_batched_advance_run_bytes: usize =
|
|
79
|
+
pub const max_batched_advance_run_bytes: usize = 65536;
|
|
80
80
|
|
|
81
81
|
/// Process-wide invalidation stamp for everything keyed on measured
|
|
82
82
|
/// text: cached advances here and retained wrap results downstream.
|