@native-sdk/cli 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/build.zig +8 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/text.ts +62 -21
  6. package/src/platform/macos/appkit_host.h +2 -0
  7. package/src/platform/macos/appkit_host.m +36 -10
  8. package/src/platform/macos/root.zig +7 -1
  9. package/src/platform/types.zig +2 -0
  10. package/src/primitives/canvas/equality.zig +3 -1
  11. package/src/primitives/canvas/events.zig +4 -0
  12. package/src/primitives/canvas/root.zig +11 -0
  13. package/src/primitives/canvas/text.zig +10 -0
  14. package/src/primitives/canvas/text_interaction.zig +164 -22
  15. package/src/primitives/canvas/text_layout.zig +107 -21
  16. package/src/primitives/canvas/text_tests.zig +86 -0
  17. package/src/primitives/canvas/ui.zig +21 -16
  18. package/src/primitives/canvas/ui_markup_reflect.zig +20 -3
  19. package/src/primitives/canvas/ui_markup_view_tests.zig +16 -0
  20. package/src/primitives/canvas/ui_tests.zig +6 -0
  21. package/src/primitives/canvas/widget_runtime.zig +1 -0
  22. package/src/primitives/canvas/widget_text_input.zig +23 -11
  23. package/src/runtime/api.zig +9 -0
  24. package/src/runtime/canvas_frame_helpers.zig +1 -0
  25. package/src/runtime/canvas_limits.zig +7 -0
  26. package/src/runtime/canvas_widget_accessibility_tests.zig +27 -1
  27. package/src/runtime/canvas_widget_clipboard_tests.zig +16 -0
  28. package/src/runtime/canvas_widget_display.zig +15 -1
  29. package/src/runtime/canvas_widget_events.zig +43 -19
  30. package/src/runtime/canvas_widget_runtime.zig +67 -10
  31. package/src/runtime/canvas_widget_state.zig +1 -0
  32. package/src/runtime/canvas_widget_text_tests.zig +1878 -70
  33. package/src/runtime/gpu_surface_events.zig +38 -0
  34. package/src/runtime/view.zig +30 -0
  35. package/src/runtime/view_widget_text.zig +1048 -10
  36. package/src/runtime/view_widget_tree.zig +2 -0
package/build.zig CHANGED
@@ -1140,6 +1140,10 @@ pub fn build(b: *std.Build) void {
1140
1140
  // An assistive client's AXFocused WRITE must move the app's
1141
1141
  // real focus, not just flip a flag on the snapshot element.
1142
1142
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "setAccessibilityFocused" },
1143
+ // Native Edit-menu validation follows the retained editor's actual
1144
+ // history directions instead of merely checking text focus.
1145
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canUndo" },
1146
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focusedText.canRedo" },
1143
1147
  });
1144
1148
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-text-ranges", "Verify AppKit GPU widget accessibility publishes text selection ranges", &.{
1145
1149
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilitySelectedTextRange" },
@@ -1198,6 +1202,10 @@ pub fn build(b: *std.Build) void {
1198
1202
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
1199
1203
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
1200
1204
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1205
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)undo:(id)sender" },
1206
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)redo:(id)sender" },
1207
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1208
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"z\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)" },
1201
1209
  // Modified horizontal navigation must bypass AppKit's selector
1202
1210
  // rewrite: the shared editor consumes the raw modifiers, and a
1203
1211
  // terminal translates them to its shell/protocol bindings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.6.2",
36
- "@native-sdk/cli-darwin-x64": "0.6.2",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.6.2",
38
- "@native-sdk/cli-linux-arm64-musl": "0.6.2",
39
- "@native-sdk/cli-linux-x64-gnu": "0.6.2",
40
- "@native-sdk/cli-linux-x64-musl": "0.6.2",
41
- "@native-sdk/cli-win32-arm64": "0.6.2",
42
- "@native-sdk/cli-win32-x64": "0.6.2"
35
+ "@native-sdk/cli-darwin-arm64": "0.6.3",
36
+ "@native-sdk/cli-darwin-x64": "0.6.3",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.6.3",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.6.3",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.6.3",
40
+ "@native-sdk/cli-linux-x64-musl": "0.6.3",
41
+ "@native-sdk/cli-win32-arm64": "0.6.3",
42
+ "@native-sdk/cli-win32-x64": "0.6.3"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.6.2",
9
+ "version": "0.6.3",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,8 @@
14
14
  // call returns a new state and never touches its inputs.
15
15
  //
16
16
  // Offsets are BYTE offsets, always snapped to UTF-8 sequence boundaries
17
- // before use, so a caret can never land inside a multi-byte character.
17
+ // before use, so a caret can never land inside a multi-byte character or
18
+ // between the two bytes of a CRLF hard-line boundary.
18
19
  // Capacity is the caller's fixed byte budget (mirror your runtime
19
20
  // TextBuffer's): an edit whose result would not fit returns null — the
20
21
  // refuse-whole contract — and `clampedInsertEvent` recovers the one case
@@ -128,6 +129,42 @@ function nextTextOffset(text: Uint8Array, offset: number): number {
128
129
  return next;
129
130
  }
130
131
 
132
+ // Caret editing treats CRLF as one hard-line boundary. Raw text ranges
133
+ // continue to use snapTextOffset so they may address either delimiter byte.
134
+ function snapTextCaretOffset(text: Uint8Array, offset: number): number {
135
+ const cursor = snapTextOffset(text, offset);
136
+ if (
137
+ cursor > 0 &&
138
+ cursor < text.length &&
139
+ text[cursor] === 0x0a &&
140
+ text[cursor - 1] === 0x0d
141
+ ) {
142
+ return cursor - 1;
143
+ }
144
+ return cursor;
145
+ }
146
+
147
+ function previousTextCaretOffset(text: Uint8Array, offset: number): number {
148
+ const previous = previousTextOffset(text, offset);
149
+ if (previous > 0 && text[previous] === 0x0a && text[previous - 1] === 0x0d) {
150
+ return previous - 1;
151
+ }
152
+ return previous;
153
+ }
154
+
155
+ function nextTextCaretOffset(text: Uint8Array, offset: number): number {
156
+ const cursor = snapTextOffset(text, offset);
157
+ if (
158
+ cursor < text.length &&
159
+ text[cursor] === 0x0d &&
160
+ cursor + 1 < text.length &&
161
+ text[cursor + 1] === 0x0a
162
+ ) {
163
+ return cursor + 2;
164
+ }
165
+ return nextTextOffset(text, cursor);
166
+ }
167
+
131
168
  function isAsciiAlphanumeric(b: number): boolean {
132
169
  return (b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5a) || (b >= 0x61 && b <= 0x7a);
133
170
  }
@@ -179,10 +216,10 @@ function nextTextWordOffset(text: Uint8Array, offset: number): number {
179
216
  return cursor;
180
217
  }
181
218
 
182
- function snapTextSelection(text: Uint8Array, selection: TextSelection): TextSelection {
219
+ function snapTextCaretSelection(text: Uint8Array, selection: TextSelection): TextSelection {
183
220
  return {
184
- anchor: snapTextOffset(text, selection.anchor),
185
- focus: snapTextOffset(text, selection.focus),
221
+ anchor: snapTextCaretOffset(text, selection.anchor),
222
+ focus: snapTextCaretOffset(text, selection.focus),
186
223
  };
187
224
  }
188
225
 
@@ -226,8 +263,9 @@ function replaceTextRange(
226
263
  function normalizeTextEditState(state: TextEditState): TextEditState {
227
264
  return {
228
265
  text: state.text,
229
- selection: snapTextSelection(state.text, state.selection),
230
- composition: state.composition !== null ? snapTextRange(state.text, state.composition) : null,
266
+ selection: snapTextCaretSelection(state.text, state.selection),
267
+ composition:
268
+ state.composition !== null ? snapTextRange(state.text, state.composition) : null,
231
269
  };
232
270
  }
233
271
 
@@ -246,7 +284,7 @@ function replaceTextEditRange(
246
284
  ): TextEditState | null {
247
285
  const result = replaceTextRange(state.text, range, replacement, capacity);
248
286
  if (result === null) return null;
249
- const cursor = snapTextOffset(
287
+ const cursor = snapTextCaretOffset(
250
288
  result.text,
251
289
  result.insertedStart + Math.min(cursorOffset, replacement.length),
252
290
  );
@@ -264,10 +302,10 @@ function setTextComposition(
264
302
  capacity: number,
265
303
  ): TextEditState | null {
266
304
  const range = activeTextReplaceRange(state);
267
- const cursor = snapTextOffset(text, cursorIn === null ? text.length : cursorIn);
305
+ const cursor = snapTextCaretOffset(text, cursorIn === null ? text.length : cursorIn);
268
306
  const result = replaceTextRange(state.text, range, text, capacity);
269
307
  if (result === null) return null;
270
- const absoluteCursor = snapTextOffset(result.text, result.insertedStart + cursor);
308
+ const absoluteCursor = snapTextCaretOffset(result.text, result.insertedStart + cursor);
271
309
  return {
272
310
  text: result.text,
273
311
  selection: { anchor: absoluteCursor, focus: absoluteCursor },
@@ -282,7 +320,10 @@ function cancelTextComposition(state: TextEditState, capacity: number): TextEdit
282
320
  if (result === null) return null;
283
321
  return {
284
322
  text: result.text,
285
- selection: { anchor: result.insertedStart, focus: result.insertedStart },
323
+ selection: snapTextCaretSelection(result.text, {
324
+ anchor: result.insertedStart,
325
+ focus: result.insertedStart,
326
+ }),
286
327
  composition: null,
287
328
  };
288
329
  }
@@ -292,13 +333,13 @@ function deleteBackwardTextEdit(state: TextEditState, capacity: number): TextEdi
292
333
  if (!rangeIsCollapsed(range, state.text.length)) {
293
334
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
294
335
  }
295
- const caret = snapTextOffset(state.text, state.selection.focus);
336
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
296
337
  if (caret === 0) {
297
338
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
298
339
  }
299
340
  return replaceTextEditRange(
300
341
  state,
301
- { start: previousTextOffset(state.text, caret), end: caret },
342
+ { start: previousTextCaretOffset(state.text, caret), end: caret },
302
343
  new Uint8Array(0),
303
344
  capacity,
304
345
  null,
@@ -311,14 +352,14 @@ function deleteForwardTextEdit(state: TextEditState, capacity: number): TextEdit
311
352
  if (!rangeIsCollapsed(range, state.text.length)) {
312
353
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
313
354
  }
314
- const caret = snapTextOffset(state.text, state.selection.focus);
355
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
315
356
  if (caret >= state.text.length) {
316
357
  const len = state.text.length;
317
358
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
318
359
  }
319
360
  return replaceTextEditRange(
320
361
  state,
321
- { start: caret, end: nextTextOffset(state.text, caret) },
362
+ { start: caret, end: nextTextCaretOffset(state.text, caret) },
322
363
  new Uint8Array(0),
323
364
  capacity,
324
365
  null,
@@ -331,7 +372,7 @@ function deleteWordBackwardTextEdit(state: TextEditState, capacity: number): Tex
331
372
  if (!rangeIsCollapsed(range, state.text.length)) {
332
373
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
333
374
  }
334
- const caret = snapTextOffset(state.text, state.selection.focus);
375
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
335
376
  if (caret === 0) {
336
377
  return { text: state.text, selection: { anchor: 0, focus: 0 }, composition: null };
337
378
  }
@@ -350,7 +391,7 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
350
391
  if (!rangeIsCollapsed(range, state.text.length)) {
351
392
  return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
352
393
  }
353
- const caret = snapTextOffset(state.text, state.selection.focus);
394
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
354
395
  if (caret >= state.text.length) {
355
396
  const len = state.text.length;
356
397
  return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
@@ -367,13 +408,13 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
367
408
 
368
409
  function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState {
369
410
  const range = selectionRange(state.selection, state.text.length);
370
- const focus = snapTextOffset(state.text, state.selection.focus);
411
+ const focus = snapTextCaretOffset(state.text, state.selection.focus);
371
412
  const collapsed = rangeIsCollapsed(range, state.text.length);
372
413
  let target: number;
373
414
  if (move.direction === "previous") {
374
- target = !move.extend && !collapsed ? range.start : previousTextOffset(state.text, focus);
415
+ target = !move.extend && !collapsed ? range.start : previousTextCaretOffset(state.text, focus);
375
416
  } else if (move.direction === "next") {
376
- target = !move.extend && !collapsed ? range.end : nextTextOffset(state.text, focus);
417
+ target = !move.extend && !collapsed ? range.end : nextTextCaretOffset(state.text, focus);
377
418
  } else if (move.direction === "previous_word") {
378
419
  target = !move.extend && !collapsed ? range.start : previousTextWordOffset(state.text, focus);
379
420
  } else if (move.direction === "next_word") {
@@ -388,7 +429,7 @@ function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState
388
429
  : { anchor: target, focus: target };
389
430
  return {
390
431
  text: state.text,
391
- selection: snapTextSelection(state.text, selection),
432
+ selection: snapTextCaretSelection(state.text, selection),
392
433
  composition: null,
393
434
  };
394
435
  }
@@ -427,7 +468,7 @@ export function applyTextInputEvent(
427
468
  case "set_selection":
428
469
  return {
429
470
  text: normalized.text,
430
- selection: snapTextSelection(normalized.text, event.selection),
471
+ selection: snapTextCaretSelection(normalized.text, event.selection),
431
472
  composition: null,
432
473
  };
433
474
  case "set_composition":
@@ -171,6 +171,8 @@ enum {
171
171
  NATIVE_SDK_APPKIT_WIDGET_STATE_REQUIRED = 1u << 6,
172
172
  NATIVE_SDK_APPKIT_WIDGET_STATE_READ_ONLY = 1u << 7,
173
173
  NATIVE_SDK_APPKIT_WIDGET_STATE_INVALID = 1u << 8,
174
+ NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_UNDO = 1u << 9,
175
+ NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_REDO = 1u << 10,
174
176
  };
175
177
 
176
178
  enum {
@@ -405,6 +405,8 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
405
405
  @property(nonatomic, assign) NativeSdkMetalSurfaceView *surfaceView;
406
406
  @property(nonatomic, assign) uint64_t widgetId;
407
407
  @property(nonatomic, assign) uint32_t actionFlags;
408
+ @property(nonatomic, assign) BOOL canUndo;
409
+ @property(nonatomic, assign) BOOL canRedo;
408
410
  - (BOOL)emitSetTextAccessibilityValue:(id)value;
409
411
  - (BOOL)emitSetSelectionAccessibilityValue:(id)value;
410
412
  @end
@@ -5538,6 +5540,8 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
5538
5540
  element.accessibilityEnabled = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_ENABLED) != 0;
5539
5541
  element.accessibilityFocused = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_FOCUSED) != 0;
5540
5542
  element.accessibilitySelected = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_SELECTED) != 0;
5543
+ element.canUndo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_UNDO) != 0;
5544
+ element.canRedo = (node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_CAN_REDO) != 0;
5541
5545
  if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_EXPANDED) != 0) {
5542
5546
  element.accessibilityExpanded = YES;
5543
5547
  } else if ((node.state_flags & NATIVE_SDK_APPKIT_WIDGET_STATE_COLLAPSED) != 0) {
@@ -7014,6 +7018,20 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7014
7018
  [self emitSelectAllTextInputCommand];
7015
7019
  }
7016
7020
 
7021
+ // The runtime owns canvas-editor history, so Edit-menu actions take the
7022
+ // same Command+Z / Command+Shift+Z route as physical keyboard events.
7023
+ - (void)undo:(id)sender {
7024
+ (void)sender;
7025
+ if (![self focusedTextAccessibilityElement]) return;
7026
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)];
7027
+ }
7028
+
7029
+ - (void)redo:(id)sender {
7030
+ (void)sender;
7031
+ if (![self focusedTextAccessibilityElement]) return;
7032
+ [self emitSyntheticKeyDownWithKey:@"z" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand | NativeSdkShortcutModifierShift)];
7033
+ }
7034
+
7017
7035
  // Edit-menu clipboard actions on the canvas: the runtime already
7018
7036
  // resolves cmd+C/X/V key events against the focused editable widget or
7019
7037
  // the view's text selection, so the menu items ride the same path as
@@ -7039,8 +7057,18 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7039
7057
  }
7040
7058
 
7041
7059
  - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
7042
- if (menuItem.action == @selector(cut:) || menuItem.action == @selector(paste:) || menuItem.action == @selector(selectAll:)) {
7043
- return [self focusedTextAccessibilityElement] != nil;
7060
+ NativeSdkWidgetAccessibilityElement *focusedText =
7061
+ (NativeSdkWidgetAccessibilityElement *)[self focusedTextAccessibilityElement];
7062
+ if (menuItem.action == @selector(undo:)) {
7063
+ return focusedText != nil && focusedText.canUndo;
7064
+ }
7065
+ if (menuItem.action == @selector(redo:)) {
7066
+ return focusedText != nil && focusedText.canRedo;
7067
+ }
7068
+ if (menuItem.action == @selector(cut:) ||
7069
+ menuItem.action == @selector(paste:) ||
7070
+ menuItem.action == @selector(selectAll:)) {
7071
+ return focusedText != nil;
7044
7072
  }
7045
7073
  return YES;
7046
7074
  }
@@ -8989,14 +9017,12 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
8989
9017
  [mainMenu addItem:editMenuItem];
8990
9018
  NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
8991
9019
  [editMenuItem setSubmenu:editMenu];
8992
- if (self.hasWebContent) {
8993
- // Undo/Redo answer only inside web content (the webview's own
8994
- // editing stack); the canvas text editor has no undo stack, so
8995
- // canvas-only apps do not show items nothing can perform.
8996
- [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
8997
- [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
8998
- [editMenu addItem:[NSMenuItem separatorItem]];
8999
- }
9020
+ // Web content answers through its native responder. A focused canvas
9021
+ // editor answers through NativeSdkGpuSurfaceView's synthetic-key
9022
+ // bridge into the runtime's per-editor history.
9023
+ [editMenu addItem:[self menuItem:@"Undo" action:@selector(undo:) key:@"z" modifiers:NSEventModifierFlagCommand]];
9024
+ [editMenu addItem:[self menuItem:@"Redo" action:@selector(redo:) key:@"Z" modifiers:NSEventModifierFlagCommand]];
9025
+ [editMenu addItem:[NSMenuItem separatorItem]];
9000
9026
  [editMenu addItem:[self menuItem:@"Cut" action:@selector(cut:) key:@"x" modifiers:NSEventModifierFlagCommand]];
9001
9027
  [editMenu addItem:[self menuItem:@"Copy" action:@selector(copy:) key:@"c" modifiers:NSEventModifierFlagCommand]];
9002
9028
  [editMenu addItem:[self menuItem:@"Paste" action:@selector(paste:) key:@"v" modifiers:NSEventModifierFlagCommand]];
@@ -375,6 +375,8 @@ const widget_state_collapsed: u32 = 1 << 5;
375
375
  const widget_state_required: u32 = 1 << 6;
376
376
  const widget_state_read_only: u32 = 1 << 7;
377
377
  const widget_state_invalid: u32 = 1 << 8;
378
+ const widget_state_can_undo: u32 = 1 << 9;
379
+ const widget_state_can_redo: u32 = 1 << 10;
378
380
  const widget_action_focus: u32 = 1 << 0;
379
381
  const widget_action_press: u32 = 1 << 1;
380
382
  const widget_action_toggle: u32 = 1 << 2;
@@ -1917,6 +1919,8 @@ fn widgetStateFlags(node: platform_mod.WidgetAccessibilityNode) u32 {
1917
1919
  if (node.required) flags |= widget_state_required;
1918
1920
  if (node.read_only) flags |= widget_state_read_only;
1919
1921
  if (node.invalid) flags |= widget_state_invalid;
1922
+ if (node.can_undo) flags |= widget_state_can_undo;
1923
+ if (node.can_redo) flags |= widget_state_can_redo;
1920
1924
  return flags;
1921
1925
  }
1922
1926
 
@@ -2651,13 +2655,15 @@ test "mac widget accessibility maps retained action flags" {
2651
2655
  }
2652
2656
 
2653
2657
  test "mac widget accessibility maps widget state flags" {
2654
- const expanded = widgetStateFlags(.{ .enabled = true, .expanded = true, .required = true, .read_only = true, .invalid = true });
2658
+ const expanded = widgetStateFlags(.{ .enabled = true, .expanded = true, .required = true, .read_only = true, .invalid = true, .can_undo = true, .can_redo = true });
2655
2659
  try std.testing.expect(expanded & widget_state_enabled != 0);
2656
2660
  try std.testing.expect(expanded & widget_state_expanded != 0);
2657
2661
  try std.testing.expect(expanded & widget_state_collapsed == 0);
2658
2662
  try std.testing.expect(expanded & widget_state_required != 0);
2659
2663
  try std.testing.expect(expanded & widget_state_read_only != 0);
2660
2664
  try std.testing.expect(expanded & widget_state_invalid != 0);
2665
+ try std.testing.expect(expanded & widget_state_can_undo != 0);
2666
+ try std.testing.expect(expanded & widget_state_can_redo != 0);
2661
2667
 
2662
2668
  const collapsed = widgetStateFlags(.{ .enabled = true, .expanded = false });
2663
2669
  try std.testing.expect(collapsed & widget_state_enabled != 0);
@@ -2154,6 +2154,8 @@ pub const WidgetAccessibilityNode = struct {
2154
2154
  required: bool = false,
2155
2155
  read_only: bool = false,
2156
2156
  invalid: bool = false,
2157
+ can_undo: bool = false,
2158
+ can_redo: bool = false,
2157
2159
  focusable: bool = false,
2158
2160
  actions: WidgetAccessibilityActions = .{},
2159
2161
  };
@@ -305,7 +305,9 @@ pub fn optionalF32Equal(a: ?f32, b: ?f32) bool {
305
305
 
306
306
  pub fn optionalTextSelectionsEqual(a: ?TextSelection, b: ?TextSelection) bool {
307
307
  if (a) |left| {
308
- if (b) |right| return left.anchor == right.anchor and left.focus == right.focus;
308
+ if (b) |right| return left.anchor == right.anchor and
309
+ left.focus == right.focus and
310
+ left.affinity == right.affinity;
309
311
  return false;
310
312
  }
311
313
  return b == null;
@@ -67,6 +67,10 @@ pub const WidgetPointerEvent = struct {
67
67
  /// may leave this at 0; gesture owners use the initiating down to
68
68
  /// decide whether to capture.
69
69
  button: i32 = 0,
70
+ /// Keyboard modifiers held for this pointer event. Text editors use
71
+ /// Shift on pointer-down to extend from the existing selection
72
+ /// anchor instead of replacing it with a collapsed caret.
73
+ modifiers: WidgetKeyboardModifiers = .{},
70
74
  };
71
75
 
72
76
  pub const WidgetKeyboardPhase = enum {
@@ -198,6 +198,8 @@ pub const TextLayoutCachePlanner = text_model.TextLayoutCachePlanner;
198
198
  pub const TextRange = text_model.TextRange;
199
199
  pub const TextSelectionRect = text_model.TextSelectionRect;
200
200
  pub const TextSelection = text_model.TextSelection;
201
+ pub const TextCaretAffinity = text_model.TextCaretAffinity;
202
+ pub const TextCaretPosition = text_model.TextCaretPosition;
201
203
  pub const TextCaretDirection = text_model.TextCaretDirection;
202
204
  pub const TextCaretMove = text_model.TextCaretMove;
203
205
  pub const TextCompositionUpdate = text_model.TextCompositionUpdate;
@@ -661,17 +663,25 @@ pub const layoutWidgetTreeWithTokens = widget_runtime.layoutWidgetTreeWithTokens
661
663
  pub const layoutTextRun = text_model.layoutTextRun;
662
664
  pub const layoutTextRunPlan = text_model.layoutTextRunPlan;
663
665
  pub const layoutTextCaretRect = text_model.layoutTextCaretRect;
666
+ pub const layoutTextCaretRectWithAffinity = text_model.layoutTextCaretRectWithAffinity;
664
667
  pub const textCaretRectForLayout = text_model.textCaretRectForLayout;
668
+ pub const textCaretRectForLayoutWithAffinity = text_model.textCaretRectForLayoutWithAffinity;
665
669
  pub const layoutTextSelectionRects = text_model.layoutTextSelectionRects;
666
670
  pub const textSelectionRectsForLayout = text_model.textSelectionRectsForLayout;
667
671
  pub const layoutTextOffsetForPoint = text_model.layoutTextOffsetForPoint;
672
+ pub const layoutTextCaretPositionForPoint = text_model.layoutTextCaretPositionForPoint;
668
673
  pub const textOffsetForLayoutPoint = text_model.textOffsetForLayoutPoint;
674
+ pub const textCaretPositionForLayoutPoint = text_model.textCaretPositionForLayoutPoint;
669
675
  pub const applyTextInputEvent = text_model.applyTextInputEvent;
670
676
  pub const snapTextOffset = text_model.snapTextOffset;
671
677
  pub const snapTextRange = text_model.snapTextRange;
672
678
  pub const snapTextSelection = text_model.snapTextSelection;
679
+ pub const snapTextCaretPosition = text_model.snapTextCaretPosition;
680
+ pub const snapTextCaretSelection = text_model.snapTextCaretSelection;
673
681
  pub const textWordSelectionAtOffset = text_model.textWordSelectionAtOffset;
674
682
  pub const textLineSelectionAtOffset = text_model.textLineSelectionAtOffset;
683
+ pub const textLineStartOffset = text_model.textLineStartOffset;
684
+ pub const textLineEndOffset = text_model.textLineEndOffset;
675
685
 
676
686
  pub const sampleCanvasRenderAnimations = render_model.sampleCanvasRenderAnimations;
677
687
 
@@ -689,6 +699,7 @@ pub const textSelectionCommandId = widget_runtime.textSelectionCommandId;
689
699
  pub const toggleWidgetKnobTravel = widget_runtime.toggleWidgetKnobTravel;
690
700
  pub const widgetControlAimPoint = widget_runtime.widgetControlAimPoint;
691
701
  pub const textSelectionForWidgetPoint = widget_runtime.textSelectionForWidgetPoint;
702
+ pub const textCaretPositionForWidgetPoint = widget_runtime.textCaretPositionForWidgetPoint;
692
703
  pub const textOffsetForWidgetPoint = widget_runtime.textOffsetForWidgetPoint;
693
704
 
694
705
  // Static text selection (click-drag select + copy in `.text` widgets;
@@ -39,11 +39,15 @@ pub const layoutTextRunPlan = text_layout.layoutTextRunPlan;
39
39
  pub const TextLineIterator = text_layout.TextLineIterator;
40
40
  pub const textBounds = text_layout.textBounds;
41
41
  pub const layoutTextCaretRect = text_layout.layoutTextCaretRect;
42
+ pub const layoutTextCaretRectWithAffinity = text_layout.layoutTextCaretRectWithAffinity;
42
43
  pub const textCaretRectForLayout = text_layout.textCaretRectForLayout;
44
+ pub const textCaretRectForLayoutWithAffinity = text_layout.textCaretRectForLayoutWithAffinity;
43
45
  pub const layoutTextSelectionRects = text_layout.layoutTextSelectionRects;
44
46
  pub const textSelectionRectsForLayout = text_layout.textSelectionRectsForLayout;
45
47
  pub const layoutTextOffsetForPoint = text_layout.layoutTextOffsetForPoint;
48
+ pub const layoutTextCaretPositionForPoint = text_layout.layoutTextCaretPositionForPoint;
46
49
  pub const textOffsetForLayoutPoint = text_layout.textOffsetForLayoutPoint;
50
+ pub const textCaretPositionForLayoutPoint = text_layout.textCaretPositionForLayoutPoint;
47
51
  pub const nextTextLineEnd = text_layout.nextTextLineEnd;
48
52
  pub const textLineRange = text_layout.textLineRange;
49
53
  pub const textLineCaretX = text_layout.textLineCaretX;
@@ -62,6 +66,8 @@ pub const isTextBreakByte = text_layout.isTextBreakByte;
62
66
  pub const TextRange = text_interaction.TextRange;
63
67
  pub const TextSelectionRect = text_interaction.TextSelectionRect;
64
68
  pub const TextSelection = text_interaction.TextSelection;
69
+ pub const TextCaretAffinity = text_interaction.TextCaretAffinity;
70
+ pub const TextCaretPosition = text_interaction.TextCaretPosition;
65
71
  pub const TextCaretDirection = text_interaction.TextCaretDirection;
66
72
  pub const TextCaretMove = text_interaction.TextCaretMove;
67
73
  pub const TextCompositionUpdate = text_interaction.TextCompositionUpdate;
@@ -70,6 +76,8 @@ pub const TextEditState = text_interaction.TextEditState;
70
76
  pub const TextBuffer = text_interaction.TextBuffer;
71
77
  pub const applyTextInputEvent = text_interaction.applyTextInputEvent;
72
78
  pub const snapTextSelection = text_interaction.snapTextSelection;
79
+ pub const snapTextCaretPosition = text_interaction.snapTextCaretPosition;
80
+ pub const snapTextCaretSelection = text_interaction.snapTextCaretSelection;
73
81
  pub const snapTextRange = text_interaction.snapTextRange;
74
82
  pub const previousTextOffset = text_interaction.previousTextOffset;
75
83
  pub const nextTextOffset = text_interaction.nextTextOffset;
@@ -77,6 +85,8 @@ pub const previousTextWordOffset = text_interaction.previousTextWordOffset;
77
85
  pub const nextTextWordOffset = text_interaction.nextTextWordOffset;
78
86
  pub const textWordSelectionAtOffset = text_interaction.textWordSelectionAtOffset;
79
87
  pub const textLineSelectionAtOffset = text_interaction.textLineSelectionAtOffset;
88
+ pub const textLineStartOffset = text_interaction.textLineStartOffset;
89
+ pub const textLineEndOffset = text_interaction.textLineEndOffset;
80
90
  pub const snapTextOffset = text_interaction.snapTextOffset;
81
91
  pub const utf8SequenceLength = text_interaction.utf8SequenceLength;
82
92
  pub const isUtf8ContinuationByte = text_interaction.isUtf8ContinuationByte;