Harden DemoType input processing - #67
Conversation
Prevent stale String.Index reuse, bound pause durations, and replay text as complete UTF-16 sequences so non-BMP characters do not trap. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Long graphemes may exceed the 20 UTF-16-unit event limit and be truncated.
Pull request overview
Harden DemoType parsing, pause handling, and Unicode text replay with regression coverage.
Changes:
- Removed stale string-index usage during control-marker cleanup.
- Added pause bounds and overflow protection.
- Improved UTF-16 replay and edge-case tests.
File summaries
| File | Summary |
|---|---|
Sources/ZoomItMacCore/SelfTest/SelfTestRunner.swift |
Added regression tests for controls, pauses, and Unicode handling. |
Sources/ZoomItMacCore/App/DemoTypeController.swift |
Hardened parsing and replay; long graphemes still require chunking to avoid truncation. |
Review details
Suppressed comments (1)
Sources/ZoomItMacCore/App/DemoTypeController.swift:557
CGEvent.keyboardSetUnicodeStringis limited to 20 UTF-16 code units per event, but a valid SwiftCharactercan contain more than 20 units (for example, a base scalar followed by many combining marks). Passing the entire grapheme here can truncate that text, so split long input into API-sized chunks without splitting surrogate pairs (and add a regression case for a long grapheme).
down?.keyboardSetUnicodeString(stringLength: buffer.count, unicodeString: baseAddress)
let up = CGEvent(keyboardEventSource: source, virtualKey: 0, keyDown: false)
up?.keyboardSetUnicodeString(stringLength: buffer.count, unicodeString: baseAddress)
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Keep each CoreGraphics Unicode event to one scalar while preserving surrogate pairs and long combining graphemes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Addressed the Unicode event-length concern in adff901. DemoType now posts one CoreGraphics keyboard event pair per Unicode scalar, so each event contains at most two UTF-16 code units and never splits a surrogate pair. The scalar sequence—and therefore combining graphemes longer than 20 UTF-16 units—is preserved across the emitted events. Added regression coverage for BMP text, a non-BMP emoji, and a 25-scalar combining grapheme. Validation passed with:
|
Fixes #66
Summary
String.Indexvalues after mutationValidation
swift run ZoomItMacSelfTestswift run -c release ZoomItMacSelfTestswift run -Xswiftc -DZOOMIT_APP_STORE ZoomItMacSelfTest