Skip to content

feat: clear key in device.io.keys sends the HID keyboard clear to wipe the focused text field - #101

Merged
gmegidish merged 2 commits into
mainfrom
feat/io-keys-clear
Oct 13, 2026
Merged

gmegidish merged 2 commits into
mainfrom
feat/io-keys-clear

Conversation

@gmegidish

@gmegidish gmegidish commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Why

Clearing a text field with cmd+a + backspace is unreliable with the 0.0.33 runner (built with Xcode 26.4). Right after a field gets focus, the first typeKey combo is dropped, so only backspace arrives and one character is deleted. This breaks Mobilewright's locator.fill() / locator.clear() on fields that already have text ("Glorpax" → "Glorpa"). The same runner code built with Xcode 27.1 delivers cmd+a fine, so the bug looks tied to the older XCTest frameworks rather than to iOS.

What

device.io.keys accepts a new key name, clear (no modifiers). It sends the HID "Keyboard Clear" key (page 0x07, usage 0x9C) through XCUIDevice performDeviceEvent:error:, which wipes the focused text field in one event. It doesn't go through typeKey, so it isn't affected by the dropped first combo. This is the same approach WebDriverAgent uses as the first step of fb_clearTextWithError (appium/appium#19389).

The event is sent by a new generic helper, sendHIDEvent(page:usage:duration:) in DeviceKitTests/XCTest/HIDEvent.swift, so other raw HID usages can reuse it. XCDeviceEvent and performDeviceEvent:error: are private and take primitive arguments, so both are looked up at runtime and called through their IMPs. Failures to find or send the event are reported as internalError.

mobilecli io keys clear --device <udid>

Test plan

  • iOS 26.5 simulator, SwiftUI TextField with text: clear right after tapping the field empties it
  • iOS 26.5 simulator: clear after typing into the field empties it
  • iOS 17.5 simulator, Settings search field: clear empties it
  • Real device, iOS 26.5: clear empties the focused field

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 0a6801b4-8489-4c53-b8b7-1c71a311ce76
📥 Commits

Reviewing files that changed from the base of the PR and between 182a036 and 7885c8b.

📒 Files selected for processing: 3
  • DeviceKitTests/JSONRPC/Handlers/IOKeys.swift
  • DeviceKitTests/XCTest/HIDEvent.swift
  • devicekit-ios.xcodeproj/project.pbxproj

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

device.io.keys recognizes case-insensitive clear input when it has no modifiers and sends it as a HID Keyboard Clear event. If the event APIs are unavailable, event creation fails, or dispatch fails, the handler throws an internal RPC error. Other inputs continue through the existing key and modifier resolution and dispatch paths.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 7885c

This adds a clear key to device.io.keys that wipes the focused text field via a HID Keyboard Clear event. Other key inputs behave as before. No merge-blocking risk was identified, though real-device behavior has not been tested.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the new clear key behavior and its HID Keyboard Clear implementation for wiping focused text fields.
Description check Passed The description directly explains the problem, implementation, API behavior, failure handling, and test coverage for the changes.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant