@native-sdk/cli 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/skill-data/native-ui/SKILL.md +17 -2
- package/src/primitives/canvas/code.zig +590 -0
- package/src/primitives/canvas/code_tests.zig +1062 -0
- package/src/primitives/canvas/layout_audit.zig +3 -1
- package/src/primitives/canvas/markdown.zig +13 -11
- package/src/primitives/canvas/markdown_tests.zig +167 -4
- package/src/primitives/canvas/root.zig +4 -2
- package/src/primitives/canvas/tests.zig +1 -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 +304 -5
- package/src/primitives/canvas/ui_markup.zig +59 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +76 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
- package/src/primitives/canvas/ui_markup_contract.zig +34 -0
- package/src/primitives/canvas/ui_markup_view.zig +73 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +85 -0
- package/src/primitives/canvas/ui_schema.zig +17 -6
- package/src/primitives/canvas/ui_schema_tests.zig +7 -6
- package/src/primitives/canvas/widget_invalidation.zig +3 -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 +30 -1
- package/src/primitives/canvas/widget_render.zig +454 -9
- package/src/primitives/canvas/widget_text_select.zig +2 -2
- package/src/primitives/canvas/widgets.zig +13 -0
- package/src/root.zig +1 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +130 -0
- package/src/runtime/canvas_widget_context_menu.zig +12 -2
- package/src/runtime/canvas_widget_events.zig +7 -1
- package/src/runtime/canvas_widget_runtime.zig +7 -2
- package/src/runtime/canvas_widget_text_tests.zig +57 -0
- package/src/runtime/view.zig +7 -3
- package/src/runtime/view_widget_text.zig +194 -4
|
@@ -501,6 +501,90 @@ test "static text drag selection highlights, copies, and clears" {
|
|
|
501
501
|
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_up, 211, 75));
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
+
test "grouped code paragraphs select and copy across chunk boundaries" {
|
|
505
|
+
var app_state: ClipboardTestApp = .{};
|
|
506
|
+
const app = app_state.app();
|
|
507
|
+
const harness = try createClipboardHarness(app);
|
|
508
|
+
defer harness.destroy(std.testing.allocator);
|
|
509
|
+
|
|
510
|
+
const first = "alpha\r\n";
|
|
511
|
+
const second = "beta";
|
|
512
|
+
const first_spans = [_]canvas.TextSpan{.{
|
|
513
|
+
.text = first,
|
|
514
|
+
.monospace = true,
|
|
515
|
+
.color = .syntax_plain,
|
|
516
|
+
}};
|
|
517
|
+
const second_spans = [_]canvas.TextSpan{.{
|
|
518
|
+
.text = second,
|
|
519
|
+
.monospace = true,
|
|
520
|
+
.color = .syntax_plain,
|
|
521
|
+
}};
|
|
522
|
+
const group_id: canvas.ObjectId = 77;
|
|
523
|
+
const children = [_]canvas.Widget{
|
|
524
|
+
.{
|
|
525
|
+
.id = 2,
|
|
526
|
+
.kind = .text,
|
|
527
|
+
.frame = geometry.RectF.init(12, 16, 220, 40),
|
|
528
|
+
.text = first,
|
|
529
|
+
.spans = &first_spans,
|
|
530
|
+
.static_text_group_id = group_id,
|
|
531
|
+
.static_text_group_offset = 0,
|
|
532
|
+
},
|
|
533
|
+
.{
|
|
534
|
+
.id = 3,
|
|
535
|
+
.kind = .text,
|
|
536
|
+
.frame = geometry.RectF.init(12, 64, 220, 40),
|
|
537
|
+
.text = second,
|
|
538
|
+
.spans = &second_spans,
|
|
539
|
+
.static_text_group_id = group_id,
|
|
540
|
+
.static_text_group_offset = first.len,
|
|
541
|
+
},
|
|
542
|
+
.{
|
|
543
|
+
.id = 4,
|
|
544
|
+
.kind = .button,
|
|
545
|
+
.frame = geometry.RectF.init(12, 128, 100, 32),
|
|
546
|
+
.text = "Clear",
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
550
|
+
const layout = try canvas.layoutWidgetTree(
|
|
551
|
+
.{ .kind = .stack, .children = &children },
|
|
552
|
+
geometry.RectF.init(0, 0, 320, 200),
|
|
553
|
+
&nodes,
|
|
554
|
+
);
|
|
555
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
556
|
+
|
|
557
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 13, 18));
|
|
558
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_drag, 231, 103));
|
|
559
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
560
|
+
try std.testing.expectEqualDeep(
|
|
561
|
+
canvas.TextSelection{ .anchor = 0, .focus = first.len },
|
|
562
|
+
retained.findById(2).?.widget.text_selection.?,
|
|
563
|
+
);
|
|
564
|
+
try std.testing.expectEqualDeep(
|
|
565
|
+
canvas.TextSelection{ .anchor = 0, .focus = second.len },
|
|
566
|
+
retained.findById(3).?.widget.text_selection.?,
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
|
|
570
|
+
var clipboard_buffer: [32]u8 = undefined;
|
|
571
|
+
try std.testing.expectEqualStrings(
|
|
572
|
+
"alpha\r\nbeta",
|
|
573
|
+
try harness.runtime.readClipboard(&clipboard_buffer),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
// Every selected chunk survives an unchanged rebuild, and pressing
|
|
577
|
+
// elsewhere clears the whole grouped highlight.
|
|
578
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
579
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
580
|
+
try std.testing.expect(retained.findById(2).?.widget.text_selection != null);
|
|
581
|
+
try std.testing.expect(retained.findById(3).?.widget.text_selection != null);
|
|
582
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 20, 140));
|
|
583
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
584
|
+
try std.testing.expect(retained.findById(2).?.widget.text_selection == null);
|
|
585
|
+
try std.testing.expect(retained.findById(3).?.widget.text_selection == null);
|
|
586
|
+
}
|
|
587
|
+
|
|
504
588
|
test "span paragraph drag selection copies the concatenated bytes" {
|
|
505
589
|
var app_state: ClipboardTestApp = .{};
|
|
506
590
|
const app = app_state.app();
|
|
@@ -539,6 +623,52 @@ test "span paragraph drag selection copies the concatenated bytes" {
|
|
|
539
623
|
try std.testing.expectEqualStrings(paragraph, copied);
|
|
540
624
|
}
|
|
541
625
|
|
|
626
|
+
test "numbered code selection copies source without decorative gutter digits" {
|
|
627
|
+
var app_state: ClipboardTestApp = .{};
|
|
628
|
+
const app = app_state.app();
|
|
629
|
+
const harness = try createClipboardHarness(app);
|
|
630
|
+
defer harness.destroy(std.testing.allocator);
|
|
631
|
+
|
|
632
|
+
const source = "alpha\nbeta";
|
|
633
|
+
const spans = [_]canvas.TextSpan{.{
|
|
634
|
+
.text = source,
|
|
635
|
+
.monospace = true,
|
|
636
|
+
.color = .syntax_plain,
|
|
637
|
+
}};
|
|
638
|
+
const children = [_]canvas.Widget{.{
|
|
639
|
+
.id = 2,
|
|
640
|
+
.kind = .text,
|
|
641
|
+
.frame = geometry.RectF.init(12, 16, 220, 60),
|
|
642
|
+
.text = source,
|
|
643
|
+
.spans = &spans,
|
|
644
|
+
.code_line_number_digits = 1,
|
|
645
|
+
}};
|
|
646
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
647
|
+
const layout = try canvas.layoutWidgetTree(
|
|
648
|
+
.{ .kind = .stack, .children = &children },
|
|
649
|
+
geometry.RectF.init(0, 0, 320, 200),
|
|
650
|
+
&nodes,
|
|
651
|
+
);
|
|
652
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
653
|
+
|
|
654
|
+
// Start inside the source column (past the renderer-owned gutter) and
|
|
655
|
+
// drag beyond the final visual line.
|
|
656
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 34, 18));
|
|
657
|
+
try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_drag, 231, 75));
|
|
658
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
659
|
+
try std.testing.expectEqualDeep(
|
|
660
|
+
canvas.TextSelection{ .anchor = 0, .focus = source.len },
|
|
661
|
+
retained.nodes[1].widget.text_selection.?,
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
|
|
665
|
+
var clipboard_buffer: [32]u8 = undefined;
|
|
666
|
+
try std.testing.expectEqualStrings(
|
|
667
|
+
source,
|
|
668
|
+
try harness.runtime.readClipboard(&clipboard_buffer),
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
|
|
542
672
|
test "focused editable selection wins copy over a stale static selection" {
|
|
543
673
|
var app_state: ClipboardTestApp = .{};
|
|
544
674
|
const app = app_state.app();
|
|
@@ -30,6 +30,7 @@ const geometry = @import("geometry");
|
|
|
30
30
|
const canvas = @import("canvas");
|
|
31
31
|
const platform = @import("../platform/root.zig");
|
|
32
32
|
const runtime_api = @import("api.zig");
|
|
33
|
+
const canvas_limits = @import("canvas_limits.zig");
|
|
33
34
|
const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
|
|
34
35
|
const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
|
|
35
36
|
|
|
@@ -225,7 +226,15 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
225
226
|
|
|
226
227
|
// 4. Static text with a live selection: Copy only.
|
|
227
228
|
const selected_id = self.views[index].canvas_widget_selected_text_id;
|
|
228
|
-
if (selected_id != 0 and selected_id
|
|
229
|
+
const selected_group_target = if (selected_id != 0 and selected_id != target.id) blk: {
|
|
230
|
+
const selected_index = self.views[index].canvasWidgetNodeIndexById(selected_id) orelse break :blk false;
|
|
231
|
+
const target_index = self.views[index].canvasWidgetNodeIndexById(target.id) orelse break :blk false;
|
|
232
|
+
const selected_widget = self.views[index].widget_layout_nodes[selected_index].widget;
|
|
233
|
+
const target_widget = self.views[index].widget_layout_nodes[target_index].widget;
|
|
234
|
+
break :blk selected_widget.static_text_group_id != 0 and
|
|
235
|
+
selected_widget.static_text_group_id == target_widget.static_text_group_id;
|
|
236
|
+
} else false;
|
|
237
|
+
if (selected_id != 0 and (selected_id == target.id or selected_group_target)) {
|
|
229
238
|
if (!has_presenter) return;
|
|
230
239
|
items[0] = .{ .id = default_item_copy, .label = "Copy" };
|
|
231
240
|
_ = try showMenu(self, app, index, .{
|
|
@@ -389,7 +398,8 @@ pub fn RuntimeCanvasWidgetContextMenu(comptime Runtime: type) type {
|
|
|
389
398
|
.terminal => try applyDefaultTerminalAction(self, app, index, pending.target_id, event.item_id),
|
|
390
399
|
.static_copy => {
|
|
391
400
|
if (event.item_id != default_item_copy) return;
|
|
392
|
-
|
|
401
|
+
var group_buffer: [canvas_limits.max_canvas_widget_text_bytes_per_view]u8 = undefined;
|
|
402
|
+
const text = self.views[index].canvasWidgetCopyText(&group_buffer) orelse return;
|
|
393
403
|
self.writeClipboard(text) catch return;
|
|
394
404
|
},
|
|
395
405
|
}
|
|
@@ -103,6 +103,12 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
|
|
|
103
103
|
}
|
|
104
104
|
if (raw.kind != .text) return press_target;
|
|
105
105
|
if (self.views[view_index].canvas_widget_selected_text_id != raw.id) return press_target;
|
|
106
|
+
if (self.views[view_index].canvas_widget_selected_text_group_id != 0 and
|
|
107
|
+
self.views[view_index].canvas_widget_selected_text_group_anchor !=
|
|
108
|
+
self.views[view_index].canvas_widget_selected_text_group_focus)
|
|
109
|
+
{
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
106
112
|
const node = self.views[view_index].widgetLayoutTree().findById(raw.id) orelse return press_target;
|
|
107
113
|
const selection = node.widget.text_selection orelse return press_target;
|
|
108
114
|
if (selection.isCollapsed(node.widget.text.len)) return press_target;
|
|
@@ -1952,7 +1958,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
|
|
|
1952
1958
|
|
|
1953
1959
|
switch (action) {
|
|
1954
1960
|
.copy => {
|
|
1955
|
-
const text = self.views[index].canvasWidgetCopyText() orelse return;
|
|
1961
|
+
const text = self.views[index].canvasWidgetCopyText(paste_buffer) orelse return;
|
|
1956
1962
|
self.writeClipboard(text) catch return;
|
|
1957
1963
|
},
|
|
1958
1964
|
.cut => {
|
|
@@ -149,6 +149,7 @@ pub const CanvasWidgetTextReconcileEntry = struct {
|
|
|
149
149
|
id: canvas.ObjectId = 0,
|
|
150
150
|
kind: canvas.WidgetKind = .text_field,
|
|
151
151
|
text: []const u8 = &.{},
|
|
152
|
+
static_text_group_id: canvas.ObjectId = 0,
|
|
152
153
|
source_text_len: usize = 0,
|
|
153
154
|
source_text_hash: u64 = 0,
|
|
154
155
|
/// The selection declared by the previous SOURCE tree, distinct from
|
|
@@ -604,6 +605,7 @@ pub fn collectCanvasWidgetTextReconcileEntries(
|
|
|
604
605
|
.id = node.widget.id,
|
|
605
606
|
.kind = node.widget.kind,
|
|
606
607
|
.text = text_storage[text_range.start..text_range.end],
|
|
608
|
+
.static_text_group_id = node.widget.static_text_group_id,
|
|
607
609
|
.source_text_len = source_text.len,
|
|
608
610
|
.source_text_hash = source_text.hash,
|
|
609
611
|
.source_text_selection = if (source_entry) |entry| entry.text_selection else null,
|
|
@@ -783,9 +785,12 @@ pub fn canvasWidgetLayoutNodeWithTextReconcileState(
|
|
|
783
785
|
|
|
784
786
|
if (copy.widget.kind == .text) {
|
|
785
787
|
// Static text selections survive rebuilds only while the source
|
|
786
|
-
// text
|
|
788
|
+
// text and its optional grouped document are byte-identical.
|
|
787
789
|
if (previous.firstWithKind(copy.widget.id, copy.widget.kind)) |entry| {
|
|
788
|
-
if (copy.widget.text_selection == null and
|
|
790
|
+
if (copy.widget.text_selection == null and
|
|
791
|
+
std.mem.eql(u8, entry.text, copy.widget.text) and
|
|
792
|
+
entry.static_text_group_id == copy.widget.static_text_group_id)
|
|
793
|
+
{
|
|
789
794
|
copy.widget.text_selection = entry.text_selection;
|
|
790
795
|
}
|
|
791
796
|
}
|
|
@@ -3744,6 +3744,63 @@ test "a widget text budget overflow on input degrades instead of exiting" {
|
|
|
3744
3744
|
} });
|
|
3745
3745
|
}
|
|
3746
3746
|
|
|
3747
|
+
test "maximal numbered code fits the retained text budget" {
|
|
3748
|
+
const TestApp = struct {
|
|
3749
|
+
fn app(self: *@This()) App {
|
|
3750
|
+
return .{ .context = self, .name = "gpu-widget-numbered-code-budget", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
3751
|
+
}
|
|
3752
|
+
};
|
|
3753
|
+
|
|
3754
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3755
|
+
defer harness.destroy(std.testing.allocator);
|
|
3756
|
+
harness.null_platform.gpu_surfaces = true;
|
|
3757
|
+
var app_state: TestApp = .{};
|
|
3758
|
+
try harness.start(app_state.app());
|
|
3759
|
+
_ = try harness.runtime.createView(.{
|
|
3760
|
+
.window_id = 1,
|
|
3761
|
+
.label = "canvas",
|
|
3762
|
+
.kind = .gpu_surface,
|
|
3763
|
+
.frame = geometry.RectF.init(0, 0, 320, 100),
|
|
3764
|
+
});
|
|
3765
|
+
|
|
3766
|
+
const source = try std.testing.allocator.alloc(
|
|
3767
|
+
u8,
|
|
3768
|
+
runtime_module.max_canvas_widget_text_bytes_per_view,
|
|
3769
|
+
);
|
|
3770
|
+
defer std.testing.allocator.free(source);
|
|
3771
|
+
@memset(source, 'x');
|
|
3772
|
+
|
|
3773
|
+
const CodeUi = canvas.Ui(enum { noop });
|
|
3774
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
3775
|
+
defer arena.deinit();
|
|
3776
|
+
var ui = CodeUi.init(arena.allocator());
|
|
3777
|
+
const tree = try ui.finalize(ui.code(.{
|
|
3778
|
+
.language = .plain,
|
|
3779
|
+
.line_numbers = true,
|
|
3780
|
+
.wrap = false,
|
|
3781
|
+
.width = 320,
|
|
3782
|
+
.height = 100,
|
|
3783
|
+
}, source));
|
|
3784
|
+
var nodes: [16]canvas.WidgetLayoutNode = undefined;
|
|
3785
|
+
const layout = try canvas.layoutWidgetTree(
|
|
3786
|
+
tree.root,
|
|
3787
|
+
geometry.RectF.init(0, 0, 320, 100),
|
|
3788
|
+
&nodes,
|
|
3789
|
+
);
|
|
3790
|
+
|
|
3791
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
3792
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
3793
|
+
var found_source = false;
|
|
3794
|
+
for (retained.nodes) |node| {
|
|
3795
|
+
if (node.widget.code_line_number_digits == 0) continue;
|
|
3796
|
+
found_source = true;
|
|
3797
|
+
try std.testing.expectEqual(@as(u8, 1), node.widget.code_line_number_digits);
|
|
3798
|
+
try std.testing.expectEqual(source.len, node.widget.text.len);
|
|
3799
|
+
try std.testing.expectEqualStrings(source, node.widget.text);
|
|
3800
|
+
}
|
|
3801
|
+
try std.testing.expect(found_source);
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3747
3804
|
/// Scan the widget's frame for a pointer location whose caret offset is
|
|
3748
3805
|
/// exactly `target`, so multi-click tests aim at text offsets without
|
|
3749
3806
|
/// hard-coding font metrics.
|
package/src/runtime/view.zig
CHANGED
|
@@ -688,10 +688,14 @@ pub const RuntimeView = struct {
|
|
|
688
688
|
/// updateCanvasWidgetInteractionFromPointer), so a pointer gliding
|
|
689
689
|
/// within one sample repaints nothing.
|
|
690
690
|
canvas_widget_hover_point: ?geometry.PointF = null,
|
|
691
|
-
/// The static `.text` widget
|
|
692
|
-
/// selection (0 = none).
|
|
693
|
-
///
|
|
691
|
+
/// The static `.text` widget where the view's active click-drag
|
|
692
|
+
/// selection began (0 = none). Ordinary paragraphs keep their range
|
|
693
|
+
/// on that widget. Bounded code paragraphs additionally share the
|
|
694
|
+
/// global group range below so one gesture can cross internal chunks.
|
|
694
695
|
canvas_widget_selected_text_id: canvas.ObjectId = 0,
|
|
696
|
+
canvas_widget_selected_text_group_id: canvas.ObjectId = 0,
|
|
697
|
+
canvas_widget_selected_text_group_anchor: usize = 0,
|
|
698
|
+
canvas_widget_selected_text_group_focus: usize = 0,
|
|
695
699
|
/// Multi-click chain state for the double/triple-click text
|
|
696
700
|
/// gestures. The runtime derives a click count from consecutive
|
|
697
701
|
/// primary pointer-downs (recorded timestamps within the interval,
|
|
@@ -1061,11 +1061,19 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
1061
1061
|
|
|
1062
1062
|
/// Click-drag selection inside one static `.text` widget. Press
|
|
1063
1063
|
/// collapses at the hit offset, drag extends from the press
|
|
1064
|
-
/// anchor.
|
|
1065
|
-
///
|
|
1066
|
-
/// document model ordering text across widgets to extend into.
|
|
1064
|
+
/// anchor. Ordinary widgets remain independently selectable;
|
|
1065
|
+
/// bounded code paragraphs opt into one ordered source group.
|
|
1067
1066
|
fn applyCanvasWidgetStaticTextPointer(self: *RuntimeView, index: usize, target_id: canvas.ObjectId, point: geometry.PointF, extend: bool) anyerror!?geometry.RectF {
|
|
1068
1067
|
const widget = self.widget_layout_nodes[index].widget;
|
|
1068
|
+
if (widget.static_text_group_id != 0) {
|
|
1069
|
+
return applyCanvasWidgetStaticTextGroupPointer(
|
|
1070
|
+
self,
|
|
1071
|
+
target_id,
|
|
1072
|
+
point,
|
|
1073
|
+
extend,
|
|
1074
|
+
widget.static_text_group_id,
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1069
1077
|
if (extend and self.canvas_widget_selected_text_id != target_id) return null;
|
|
1070
1078
|
const current_selection = widget.text_selection orelse canvas.TextSelection.collapsed(0);
|
|
1071
1079
|
const anchor: ?usize = if (extend) current_selection.anchor else null;
|
|
@@ -1074,11 +1082,130 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
1074
1082
|
|
|
1075
1083
|
self.widget_layout_nodes[index].widget.text_selection = next_selection;
|
|
1076
1084
|
self.canvas_widget_selected_text_id = target_id;
|
|
1085
|
+
self.canvas_widget_selected_text_group_id = 0;
|
|
1086
|
+
self.canvas_widget_selected_text_group_anchor = 0;
|
|
1087
|
+
self.canvas_widget_selected_text_group_focus = 0;
|
|
1077
1088
|
try self.refreshCanvasWidgetSemantics();
|
|
1078
1089
|
self.widget_revision += 1;
|
|
1079
1090
|
return self.canvasWidgetDirtyBounds(index, widget.frame);
|
|
1080
1091
|
}
|
|
1081
1092
|
|
|
1093
|
+
fn applyCanvasWidgetStaticTextGroupPointer(
|
|
1094
|
+
self: *RuntimeView,
|
|
1095
|
+
target_id: canvas.ObjectId,
|
|
1096
|
+
point: geometry.PointF,
|
|
1097
|
+
extend: bool,
|
|
1098
|
+
group_id: canvas.ObjectId,
|
|
1099
|
+
) anyerror!?geometry.RectF {
|
|
1100
|
+
if (extend and
|
|
1101
|
+
(self.canvas_widget_selected_text_id != target_id or
|
|
1102
|
+
self.canvas_widget_selected_text_group_id != group_id))
|
|
1103
|
+
{
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
var point_index: ?usize = null;
|
|
1108
|
+
var point_offset: usize = 0;
|
|
1109
|
+
var best_distance = std.math.inf(f32);
|
|
1110
|
+
const layout = self.widgetLayoutTree();
|
|
1111
|
+
for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, candidate_index| {
|
|
1112
|
+
const candidate = node.widget;
|
|
1113
|
+
if (candidate.static_text_group_id != group_id or
|
|
1114
|
+
canvasWidgetLayoutNodeHidden(layout, candidate_index) or
|
|
1115
|
+
!canvas.widgetStaticTextSelectable(candidate))
|
|
1116
|
+
{
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
const frame = candidate.frame.normalized();
|
|
1120
|
+
const dx = if (point.x < frame.x)
|
|
1121
|
+
frame.x - point.x
|
|
1122
|
+
else if (point.x > frame.maxX())
|
|
1123
|
+
point.x - frame.maxX()
|
|
1124
|
+
else
|
|
1125
|
+
0;
|
|
1126
|
+
const dy = if (point.y < frame.y)
|
|
1127
|
+
frame.y - point.y
|
|
1128
|
+
else if (point.y > frame.maxY())
|
|
1129
|
+
point.y - frame.maxY()
|
|
1130
|
+
else
|
|
1131
|
+
0;
|
|
1132
|
+
const distance = dx * dx + dy * dy;
|
|
1133
|
+
if (distance > best_distance) continue;
|
|
1134
|
+
const local = canvas.staticTextSelectionForWidgetPoint(
|
|
1135
|
+
candidate,
|
|
1136
|
+
point,
|
|
1137
|
+
null,
|
|
1138
|
+
self.widget_tokens,
|
|
1139
|
+
) orelse continue;
|
|
1140
|
+
if (distance == best_distance and point_index != null) continue;
|
|
1141
|
+
best_distance = distance;
|
|
1142
|
+
point_index = candidate_index;
|
|
1143
|
+
point_offset = local.focus;
|
|
1144
|
+
}
|
|
1145
|
+
const selected_index = point_index orelse return null;
|
|
1146
|
+
const selected_widget = self.widget_layout_nodes[selected_index].widget;
|
|
1147
|
+
const focus = selected_widget.static_text_group_offset + point_offset;
|
|
1148
|
+
const anchor = if (extend)
|
|
1149
|
+
self.canvas_widget_selected_text_group_anchor
|
|
1150
|
+
else
|
|
1151
|
+
focus;
|
|
1152
|
+
const selection_start = @min(anchor, focus);
|
|
1153
|
+
const selection_end = @max(anchor, focus);
|
|
1154
|
+
|
|
1155
|
+
var dirty: ?geometry.RectF = null;
|
|
1156
|
+
var changed = false;
|
|
1157
|
+
for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |*node, candidate_index| {
|
|
1158
|
+
const candidate = node.widget;
|
|
1159
|
+
if (candidate.static_text_group_id != group_id) {
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
const source_start = candidate.static_text_group_offset;
|
|
1163
|
+
const source_end = source_start +| candidate.text.len;
|
|
1164
|
+
const next_selection: ?canvas.TextSelection = if (selection_start == selection_end)
|
|
1165
|
+
if (candidate_index == selected_index)
|
|
1166
|
+
canvas.TextSelection.collapsed(point_offset)
|
|
1167
|
+
else
|
|
1168
|
+
null
|
|
1169
|
+
else if (@max(selection_start, source_start) < @min(selection_end, source_end))
|
|
1170
|
+
.{
|
|
1171
|
+
.anchor = @max(selection_start, source_start) - source_start,
|
|
1172
|
+
.focus = @min(selection_end, source_end) - source_start,
|
|
1173
|
+
}
|
|
1174
|
+
else
|
|
1175
|
+
null;
|
|
1176
|
+
const current_selection = candidate.text_selection;
|
|
1177
|
+
const same = if (current_selection) |current|
|
|
1178
|
+
if (next_selection) |next|
|
|
1179
|
+
canvasTextSelectionsEqual(current, next)
|
|
1180
|
+
else
|
|
1181
|
+
false
|
|
1182
|
+
else
|
|
1183
|
+
next_selection == null;
|
|
1184
|
+
if (same) continue;
|
|
1185
|
+
node.widget.text_selection = next_selection;
|
|
1186
|
+
changed = true;
|
|
1187
|
+
dirty = unionRects(
|
|
1188
|
+
dirty,
|
|
1189
|
+
self.canvasWidgetDirtyBounds(candidate_index, candidate.frame),
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
if (!changed and
|
|
1193
|
+
self.canvas_widget_selected_text_id == target_id and
|
|
1194
|
+
self.canvas_widget_selected_text_group_anchor == anchor and
|
|
1195
|
+
self.canvas_widget_selected_text_group_focus == focus)
|
|
1196
|
+
{
|
|
1197
|
+
return null;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
self.canvas_widget_selected_text_id = target_id;
|
|
1201
|
+
self.canvas_widget_selected_text_group_id = group_id;
|
|
1202
|
+
self.canvas_widget_selected_text_group_anchor = anchor;
|
|
1203
|
+
self.canvas_widget_selected_text_group_focus = focus;
|
|
1204
|
+
try self.refreshCanvasWidgetSemantics();
|
|
1205
|
+
self.widget_revision += 1;
|
|
1206
|
+
return dirty;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1082
1209
|
/// Drop the view's static text selection (pointer pressed
|
|
1083
1210
|
/// elsewhere, or the copy source went away). Returns the dirty
|
|
1084
1211
|
/// bounds of the widget that lost its highlight.
|
|
@@ -1086,6 +1213,31 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
1086
1213
|
const id = self.canvas_widget_selected_text_id;
|
|
1087
1214
|
if (id == 0) return null;
|
|
1088
1215
|
self.canvas_widget_selected_text_id = 0;
|
|
1216
|
+
const group_id = self.canvas_widget_selected_text_group_id;
|
|
1217
|
+
self.canvas_widget_selected_text_group_id = 0;
|
|
1218
|
+
self.canvas_widget_selected_text_group_anchor = 0;
|
|
1219
|
+
self.canvas_widget_selected_text_group_focus = 0;
|
|
1220
|
+
if (group_id != 0) {
|
|
1221
|
+
var dirty: ?geometry.RectF = null;
|
|
1222
|
+
var changed = false;
|
|
1223
|
+
for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |*node, index| {
|
|
1224
|
+
if (node.widget.static_text_group_id != group_id or
|
|
1225
|
+
node.widget.text_selection == null)
|
|
1226
|
+
{
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
node.widget.text_selection = null;
|
|
1230
|
+
changed = true;
|
|
1231
|
+
dirty = unionRects(
|
|
1232
|
+
dirty,
|
|
1233
|
+
self.canvasWidgetDirtyBounds(index, node.widget.frame),
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
if (!changed) return null;
|
|
1237
|
+
try self.refreshCanvasWidgetSemantics();
|
|
1238
|
+
self.widget_revision += 1;
|
|
1239
|
+
return dirty;
|
|
1240
|
+
}
|
|
1089
1241
|
const index = self.canvasWidgetNodeIndexById(id) orelse return null;
|
|
1090
1242
|
if (self.widget_layout_nodes[index].widget.text_selection == null) return null;
|
|
1091
1243
|
self.widget_layout_nodes[index].widget.text_selection = null;
|
|
@@ -1098,7 +1250,7 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
1098
1250
|
/// focused editable widget's selection or focused terminal's
|
|
1099
1251
|
/// emulator selection when it has one, else the view's static
|
|
1100
1252
|
/// text selection.
|
|
1101
|
-
pub fn canvasWidgetCopyText(self: *const RuntimeView) ?[]const u8 {
|
|
1253
|
+
pub fn canvasWidgetCopyText(self: *const RuntimeView, group_buffer: []u8) ?[]const u8 {
|
|
1102
1254
|
if (self.canvas_widget_focused_id != 0) {
|
|
1103
1255
|
if (self.canvasWidgetNodeIndexById(self.canvas_widget_focused_id)) |index| {
|
|
1104
1256
|
const focused = self.widget_layout_nodes[index].widget;
|
|
@@ -1111,11 +1263,49 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
|
|
|
1111
1263
|
if (canvasWidgetSelectionSliceById(self, self.canvas_widget_focused_id, true)) |slice| return slice;
|
|
1112
1264
|
}
|
|
1113
1265
|
if (self.canvas_widget_selected_text_id != 0) {
|
|
1266
|
+
if (self.canvas_widget_selected_text_group_id != 0) {
|
|
1267
|
+
return canvasWidgetStaticTextGroupCopy(self, group_buffer);
|
|
1268
|
+
}
|
|
1114
1269
|
if (canvasWidgetSelectionSliceById(self, self.canvas_widget_selected_text_id, false)) |slice| return slice;
|
|
1115
1270
|
}
|
|
1116
1271
|
return null;
|
|
1117
1272
|
}
|
|
1118
1273
|
|
|
1274
|
+
fn canvasWidgetStaticTextGroupCopy(self: *const RuntimeView, output: []u8) ?[]const u8 {
|
|
1275
|
+
const group_id = self.canvas_widget_selected_text_group_id;
|
|
1276
|
+
if (group_id == 0) return null;
|
|
1277
|
+
const start = @min(
|
|
1278
|
+
self.canvas_widget_selected_text_group_anchor,
|
|
1279
|
+
self.canvas_widget_selected_text_group_focus,
|
|
1280
|
+
);
|
|
1281
|
+
const end = @max(
|
|
1282
|
+
self.canvas_widget_selected_text_group_anchor,
|
|
1283
|
+
self.canvas_widget_selected_text_group_focus,
|
|
1284
|
+
);
|
|
1285
|
+
if (start >= end or end - start > output.len) return null;
|
|
1286
|
+
var copied: usize = 0;
|
|
1287
|
+
for (self.widget_layout_nodes[0..self.widget_layout_node_count]) |node| {
|
|
1288
|
+
const widget = node.widget;
|
|
1289
|
+
if (widget.static_text_group_id != group_id) {
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
const source_start = widget.static_text_group_offset;
|
|
1293
|
+
const source_end = source_start +| widget.text.len;
|
|
1294
|
+
const copy_start = @max(start, source_start);
|
|
1295
|
+
const copy_end = @min(end, source_end);
|
|
1296
|
+
if (copy_start >= copy_end) continue;
|
|
1297
|
+
const destination_start = copy_start - start;
|
|
1298
|
+
const len = copy_end - copy_start;
|
|
1299
|
+
@memcpy(
|
|
1300
|
+
output[destination_start..][0..len],
|
|
1301
|
+
widget.text[copy_start - source_start ..][0..len],
|
|
1302
|
+
);
|
|
1303
|
+
copied += len;
|
|
1304
|
+
}
|
|
1305
|
+
if (copied != end - start) return null;
|
|
1306
|
+
return output[0 .. end - start];
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1119
1309
|
fn canvasWidgetSelectionSliceById(self: *const RuntimeView, id: canvas.ObjectId, editable_only: bool) ?[]const u8 {
|
|
1120
1310
|
const index = self.canvasWidgetNodeIndexById(id) orelse return null;
|
|
1121
1311
|
const widget = self.widget_layout_nodes[index].widget;
|