mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* feat(ios): match iOS 26 Liquid Glass keyboard geometry, palette, and Hex key controls
* feat(ios): add 3-slot suggestion strip, cautious autocorrect, and typing gestures
* test(ios): cover iOS 26 keyboard metrics, autocorrect, gestures, and hosted stage
* iOS: move Hex for iPhone to Anomaly's Apple team
(cherry picked from commit 09061502ff)
* Cut Hex Mobile TestFlight betas with a dedicated release tag
Connect the Anomaly app record and pin the mobile package graph. Cut ios-beta prereleases from dev at the scheduled windows or on dispatch, skipping unchanged mobile inputs instead of creating desktop releases or allocating build numbers locally. Prepare the generated project for the Cloud archive after clone.
Verified actionlint, duplicate and desktop-only skips, strict SwiftPM resolution, and an unsigned Release device archive containing the app, keyboard, and widgets. First Xcode Cloud onboarding and signed distribution are still pending.
* Dictate inside the iOS keyboard without opening Hex (probe)
When no warm session is running, the keyboard now records and transcribes on its own instead of opening Hex. iOS refuses to record from a keyboard extension directly (audiomxd: extension lacks the record-audio entitlement), so capture runs through getUserMedia in a hidden WKWebView, whose media process records under Hex's microphone permission. PCM is streamed to Swift, written to a WAV file, and transcribed with on-device Apple Speech (SpeechTranscriber), downloading its assets from the keyboard on first use. Steps and memory are logged to the App Group.
Replaces the cold-start handoff that opened Hex and returned to the host app. Not gated yet: needs an Experiments toggle before it ships. Verified on an iPhone 17 Pro (iOS 27.2) with Hex quit: dictation in Mail/Notes inserted text; the keyboard's footprint was about 58 MB with 118 MB headroom. Unsigned simulator tests were not run.
* Regenerate the keyboard Info.plist with its microphone and speech descriptions
XcodeGen writes these from project.yml; the previous commit changed project.yml without the generated plist. Verified by building for the device.
* Start in-keyboard dictation from the full keyboard's Hex key
Holding the Hex key without a warm session opened Hex through the cold-start handoff; it now records and transcribes inside the keyboard when that path is available, and only falls back to opening Hex otherwise. Verified it builds and installs on the iPhone 17 Pro.
* Dictate with a tap on the Hex key and the bar's Hex mark
The full keyboard's Hex key ignored taps and needed a 0.35 s hold; a tap now dictates too (sliding still opens the style menu). The dictation bar's Hex mark opened Hex through the cold-start handoff; with no warm session it now starts in-keyboard dictation instead. Removes the stray-tap-does-nothing guard because Ryan wants the key to act like a dictation button.
Verified HexKeyGestureTests (5 passed) in the iPhone 18 Pro simulator and installed on the iPhone 17 Pro.
* Offer Paste and one-time-code help in the full keyboard's strip
When something was copied in the last 3 minutes and not yet pasted from the keyboard, the empty strip shows the system Paste button (UIPasteControl), which hands the clipboard over only on tap, so iOS never shows its paste prompt; nothing reads the clipboard before then. In one-time-code fields the strip also offers switching keyboards, because iOS gives codes from Messages and Mail only to its own keyboard. Copies seen and pasted are tracked by changeCount in the App Group. UIPasteControl's configuration is immutable, so a palette change replaces the control (setting colors on it raised NSInternalInconsistencyException in FullKeyboardEngineTests).
Verified the full HEXMobileTests suite passes on the iPhone 18 Pro simulator and the build installs on the iPhone 17 Pro; the Paste button itself is not yet tried on the device.
* Describe in-keyboard dictation in the iOS README
The status paragraph said the keyboard never touches the microphone; it now records through WebKit and transcribes with Apple Speech when no warm session runs. The cold-start handoff remains only before iOS 26.
---------
Co-authored-by: Kit Langton <kit.langton@gmail.com>
257 lines
8.8 KiB
Swift
257 lines
8.8 KiB
Swift
import UIKit
|
|
import XCTest
|
|
@testable import HEX
|
|
|
|
@MainActor
|
|
final class FullKeyboardEngineTests: XCTestCase {
|
|
private var target: FixtureTextTarget!
|
|
private var engine: FullKeyboardEngine!
|
|
private var now: TimeInterval = 100
|
|
private var suiteName: String!
|
|
private var defaults: UserDefaults!
|
|
|
|
override func setUp() async throws {
|
|
suiteName = "FullKeyboardEngineTests-\(UUID().uuidString)"
|
|
defaults = UserDefaults(suiteName: suiteName)!
|
|
target = FixtureTextTarget()
|
|
target.autocapitalizationType = UITextAutocapitalizationType.none
|
|
let ac = AutocorrectEngine(learnedWords: LearnedWordsStore(defaults: defaults))
|
|
engine = FullKeyboardEngine(target: target, autocorrect: ac)
|
|
engine.width = 393
|
|
engine.clock = { [unowned self] in self.now }
|
|
engine.configureForField()
|
|
}
|
|
|
|
override func tearDown() async throws {
|
|
defaults.removePersistentDomain(forName: suiteName)
|
|
}
|
|
|
|
private func point(_ kind: KeyKind) -> CGPoint {
|
|
let key = engine.layout.key(kind)!
|
|
return CGPoint(x: key.frame.midX, y: key.frame.midY)
|
|
}
|
|
|
|
private func down(_ id: Int, _ kind: KeyKind) { engine.touchBegan(id: id, at: point(kind)) }
|
|
private func up(_ id: Int, _ kind: KeyKind) { engine.touchEnded(id: id, at: point(kind)) }
|
|
|
|
private func tap(_ kind: KeyKind) {
|
|
let at = point(kind)
|
|
engine.touchBegan(id: 1, at: at)
|
|
engine.touchEnded(id: 1, at: at)
|
|
}
|
|
|
|
private func type(_ text: String) {
|
|
for ch in text {
|
|
tap(ch == " " ? .space : .character(String(ch)))
|
|
now += 0.5
|
|
}
|
|
}
|
|
|
|
func testRolloverKeepsOrder() {
|
|
down(1, .character("t"))
|
|
down(2, .character("h"))
|
|
up(1, .character("t"))
|
|
up(2, .character("h"))
|
|
XCTAssertEqual(target.text, "th")
|
|
}
|
|
|
|
func testRolloverWhenTheSecondKeyLiftsFirst() {
|
|
down(1, .character("t"))
|
|
down(2, .character("h"))
|
|
up(2, .character("h"))
|
|
up(1, .character("t"))
|
|
XCTAssertEqual(target.text, "th")
|
|
}
|
|
|
|
func testSlidingToAnotherKeyTypesWhereTheFingerLifts() {
|
|
down(1, .character("f"))
|
|
engine.touchMoved(id: 1, to: point(.character("g")))
|
|
XCTAssertEqual(engine.previewKey?.kind, .character("g"))
|
|
up(1, .character("g"))
|
|
XCTAssertEqual(target.text, "g")
|
|
}
|
|
|
|
func testShiftChordAndOneShot() {
|
|
down(1, .shift)
|
|
down(2, .character("a"))
|
|
up(2, .character("a"))
|
|
down(3, .character("b"))
|
|
up(3, .character("b"))
|
|
up(1, .shift)
|
|
tap(.character("c"))
|
|
XCTAssertEqual(target.text, "ABc")
|
|
|
|
tap(.shift)
|
|
tap(.character("d"))
|
|
tap(.character("e"))
|
|
XCTAssertEqual(target.text, "ABcDe")
|
|
}
|
|
|
|
func testDoubleTapShiftLocks() {
|
|
tap(.shift)
|
|
now += 0.1
|
|
tap(.shift)
|
|
type("hi")
|
|
XCTAssertEqual(target.text, "HI")
|
|
XCTAssertEqual(engine.shift.state, .locked)
|
|
}
|
|
|
|
func testHoldNumbersSlideToADigitAndLetGo() {
|
|
down(1, .layerSwitch(.numbers))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
engine.touchMoved(id: 1, to: point(.character("7")))
|
|
engine.touchEnded(id: 1, at: point(.character("7")))
|
|
XCTAssertEqual(target.text, "7")
|
|
XCTAssertEqual(engine.layout.layer, .letters)
|
|
}
|
|
|
|
func testNumbersStayUntilSpace() {
|
|
tap(.layerSwitch(.numbers))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
tap(.character("4"))
|
|
tap(.character("2"))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
tap(.space)
|
|
XCTAssertEqual(engine.layout.layer, .letters)
|
|
XCTAssertEqual(target.text, "42 ")
|
|
}
|
|
|
|
func testDoubleSpaceTypesAPeriod() {
|
|
type("ok")
|
|
tap(.space)
|
|
now += 0.2
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok. ")
|
|
now += 0.2
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok. ", "a third space is just a space")
|
|
}
|
|
|
|
func testSlowDoubleSpaceStaysTwoSpaces() {
|
|
type("ok")
|
|
tap(.space)
|
|
now += 0.5
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok ")
|
|
}
|
|
|
|
func testSentenceAutoCapitalization() {
|
|
target.autocapitalizationType = .sentences
|
|
engine.configureForField()
|
|
XCTAssertEqual(engine.shift.state, .on)
|
|
type("hi")
|
|
tap(.space)
|
|
now += 0.2
|
|
tap(.space)
|
|
type("there")
|
|
XCTAssertEqual(target.text, "Hi. There")
|
|
}
|
|
|
|
func testAcceleratingDeleteRampAndWordDelete() {
|
|
type("hello world")
|
|
down(1, .delete)
|
|
XCTAssertEqual(target.text, "hello worl")
|
|
// Initial repeat deletes 1 char.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.repeatDelay)
|
|
XCTAssertEqual(target.text, "hello wor")
|
|
// Accelerated repeat deletes 2 chars per tick.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.fastRepeatAfter)
|
|
XCTAssertEqual(target.text, "hello w")
|
|
// After 1.4 s, removes whole words backward.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.wordDeleteAfter)
|
|
XCTAssertEqual(target.text, "hello ")
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.wordDeleteAfter)
|
|
XCTAssertEqual(target.text, "")
|
|
up(1, .delete)
|
|
}
|
|
|
|
func testLongPressAccentPickerSelectsAndUppercaseWorks() {
|
|
tap(.shift)
|
|
down(1, .character("e"))
|
|
XCTAssertTrue(engine.openAccentMenuIfEligible(forTouch: 1))
|
|
let menu = try! XCTUnwrap(engine.activeAccentMenu)
|
|
XCTAssertNil(engine.previewKey, "single-key balloon hides while accent picker is open")
|
|
XCTAssertEqual(menu.options.first, "E")
|
|
// Slide to index 2 ("É").
|
|
let cell = menu.cellFrames[2]
|
|
engine.touchMoved(id: 1, to: CGPoint(x: cell.midX, y: cell.midY))
|
|
engine.touchEnded(id: 1, at: CGPoint(x: cell.midX, y: cell.midY))
|
|
XCTAssertNil(engine.activeAccentMenu)
|
|
XCTAssertEqual(target.text, "É")
|
|
XCTAssertEqual(engine.shift.state, .off)
|
|
}
|
|
|
|
func testSpacebarTrackpadMovesCaretWithoutInsertingSpace() {
|
|
type("helo")
|
|
let spaceStart = point(.space)
|
|
engine.touchBegan(id: 1, at: spaceStart)
|
|
// Enter trackpad mode (-12 pt) then drag left by 16 pt (-2 chars: before "lo").
|
|
let enterPoint = CGPoint(x: spaceStart.x - 12, y: spaceStart.y)
|
|
engine.touchMoved(id: 1, to: enterPoint)
|
|
XCTAssertTrue(engine.isTrackpadActive)
|
|
engine.touchMoved(id: 1, to: CGPoint(x: enterPoint.x - 16, y: spaceStart.y))
|
|
engine.touchEnded(id: 1, at: CGPoint(x: enterPoint.x - 16, y: spaceStart.y))
|
|
XCTAssertFalse(engine.isTrackpadActive)
|
|
XCTAssertEqual(target.cursorIndex, 2)
|
|
tap(.character("l"))
|
|
XCTAssertEqual(target.text, "hello")
|
|
}
|
|
|
|
func testEnablesReturnKeyAutomaticallyBlocksEmptyField() {
|
|
target.enablesReturnKeyAutomatically = true
|
|
tap(.returnKey)
|
|
XCTAssertEqual(target.text, "")
|
|
type("ok")
|
|
tap(.returnKey)
|
|
XCTAssertEqual(target.text, "ok\n")
|
|
}
|
|
|
|
func testRecordingPanelAllocatesLazilyAndTearsDownOnIdle() {
|
|
let model = KeyboardViewModel()
|
|
let view = FullKeyboardView(model: model, target: target)
|
|
view.frame = CGRect(x: 0, y: 0, width: 393, height: 254)
|
|
view.layoutIfNeeded()
|
|
XCTAssertFalse(view.hasAllocatedRecordingPanel, "no Metal scope allocated while typing")
|
|
|
|
let t: TimeInterval = 1_000
|
|
model.applyBridgeState(
|
|
hasFullAccess: true,
|
|
snapshot: KeyboardSnapshot(state: .recording, heartbeat: t, expiresAt: t + 60, recordingStartedAt: t - 1, jobID: "j1"),
|
|
isModelInstalled: true,
|
|
style: .polished,
|
|
returnAppID: nil,
|
|
now: t,
|
|
clearPending: false,
|
|
animated: false
|
|
)
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertTrue(view.hasAllocatedRecordingPanel)
|
|
|
|
model.applyBridgeState(
|
|
hasFullAccess: true,
|
|
snapshot: KeyboardSnapshot(state: .ready, heartbeat: t + 1, expiresAt: t + 60),
|
|
isModelInstalled: true,
|
|
style: .polished,
|
|
returnAppID: nil,
|
|
now: t + 1,
|
|
clearPending: true,
|
|
animated: false
|
|
)
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertFalse(view.hasAllocatedRecordingPanel, "Metal scope torn down once recording ends")
|
|
}
|
|
|
|
func testEmailFieldShowsAtAndDot() {
|
|
target.keyboardType = .emailAddress
|
|
engine.configureForField()
|
|
tap(.character("@"))
|
|
tap(.character("."))
|
|
XCTAssertEqual(target.text, "@.")
|
|
}
|
|
|
|
func testNumberPadOpensOnNumbers() {
|
|
target.keyboardType = .numberPad
|
|
engine.configureForField()
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
}
|
|
}
|