hex/ios/HEXShared/FullKeyboard/FullKeyboardSettings.swift
Ryan Vogel 5b35eb98f5
iOS: Spatial autocorrect is on by default, under Settings › Keyboard (#2097)
Spatial autocorrect (#2059, tuned in #2091) cut English output word errors
from 10.4% to 6.5% and Spanish from 19.1% to 8.8%, so it graduates from
Experiments and is on for English and Spanish layouts by default. Other
layouts keep the dictionary engine in their own language, as before.

- Default: FullKeyboardSettings.spatialAutocorrect reads
  experiments.spatialAutocorrect as object-or-true (was bool(forKey:),
  unset meaning off). Only the Experiments switch ever wrote that key, and
  only on a change, so unset means never touched: testers who never set it
  get it on, those who turned it off (stored false) stay off, and those who
  turned it on stay on. No new key or migration marker is needed; the key
  keeps its old name, as experiments.fullKeyboard did.
- Settings › Keyboard: "Spatial autocorrect" now sits under Autocorrect,
  shown only while Autocorrect is on, with "Uses where you tap, in English
  and Spanish" (one line; zh-Hans added). Rebased onto #2093, so it sits
  above Suggest swear words; the never-suggest filter still applies to
  Spatial's readings.
- Settings › Experiments: the Spatial row and its two strings are removed
  ("Reads where your taps land…", "Needs the full keyboard with Autocorrect
  on"). Experiments still has Emoji and Clean up with Apple Intelligence,
  so its home row stays.
- The settings-<page> scene fixture writes spatialAutocorrect = true.
- README: where the switch lives, its default and the stored key's meaning.

Verified on an iPhone 17 simulator (iOS 27.2):
- xcodebuild test: 301 tests, 1 skipped (needs HEX_SPEECH_CLIPS), 0
  failures. One earlier full run had testAcceptedJobDeliversTranscript-
  EvenWhenWarmSessionCloses fail on timing; it passed 3/3 alone and in the
  next full run.
- Fresh install, real HEXKeyboard in a hosted field, App Group key unset:
  "ofthw" + space gave "Of the", and "fucj" gave "duck", not the swear word.
- Turned off through Settings › Keyboard: stored false, and after quitting,
  a simulator reboot and two relaunches "ofthw" stayed "Ofthw".
- Memory (Release, Full Access, 3 runs each, off vs on): no difference
  (keyboard phys_footprint 24.5-24.8 MB after open, 33-34 MB at the Hex
  key's touch-down, peak 42-46 MB in both). Since #2091 the model is
  memory-mapped at keyboard open for next-letter odds either way; the
  decoder only adds a struct over it and builds your words lazily.
2026-11-20 20:39:27 +00:00

101 lines
4.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
/// The full keyboard's switches in the shared App Group.
///
/// Without Full Access an iPhone may not let the keyboard read the App Group (the simulator
/// does), so every switch's default must work there: the full keyboard, which types
/// without Full Access.
@MainActor
struct FullKeyboardSettings {
static let launchArgument = "--experiment-full-keyboard"
static let emojiLaunchArgument = "--experiment-emoji"
/// Simulator scenes pass `--keyboard dictation-bar` (or `full`) to pick the keyboard.
static let keyboardLaunchArgument = "--keyboard"
private enum Key {
static let fullKeyboard = "experiments.fullKeyboard"
static let autocorrect = "settings.keyboardAutocorrect"
static let spatialAutocorrect = "experiments.spatialAutocorrect"
static let keyPopups = "settings.keyboardKeyPopups"
static let haptics = "settings.keyboardHaptics"
static let suggestSwearWords = "settings.keyboardSuggestSwearWords"
static let emoji = "experiments.emoji"
}
private let defaults: UserDefaults?
init(defaults: UserDefaults? = UserDefaults(suiteName: KeyboardBridge.appGroup)) {
self.defaults = defaults
}
/// Settings › Keyboard: Full (true) or Dictation bar (false). The full keyboard (letters,
/// numbers, symbols, autocorrect and the Hex key) by default; the dictation bar (space,
/// delete, return and Dictate) only once it was chosen. Stored as
/// `experiments.fullKeyboard`, from when the full keyboard was an experiment: unset or
/// true is the full keyboard and false the dictation bar, so testers who never touched
/// the experiment get the full keyboard and those who turned it off keep the bar.
var isEnabled: Bool {
get { defaults?.object(forKey: Key.fullKeyboard) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.fullKeyboard) }
}
/// Cautious autocorrect on space. On by default.
var autocorrect: Bool {
get { defaults?.object(forKey: Key.autocorrect) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.autocorrect) }
}
/// Settings › Keyboard › Spatial autocorrect: autocorrect reads your taps with a language
/// model (`TypingDecoder`) instead of `UITextChecker`'s one-edit guesses, in English and
/// Spanish. On by default. Stored as `experiments.spatialAutocorrect`, from when it was an
/// experiment (off by default) that only its switch ever wrote: unset or true is on and
/// false off, so testers who never touched it get it and those who turned it off keep it off.
var spatialAutocorrect: Bool {
get { defaults?.object(forKey: Key.spatialAutocorrect) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.spatialAutocorrect) }
}
/// Suggestions and autocorrect may offer swear words (`OffensiveWords`); slurs never.
/// Off by default, like Apple's keyboard.
var suggestSwearWords: Bool {
get { defaults?.bool(forKey: Key.suggestSwearWords) ?? false }
nonmutating set { defaults?.set(newValue, forKey: Key.suggestSwearWords) }
}
/// The enlarged letter that pops up over a pressed key. On by default.
var keyPopups: Bool {
get { defaults?.object(forKey: Key.keyPopups) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.keyPopups) }
}
/// A light tap under your finger for each key press. On by default.
var haptics: Bool {
get { defaults?.object(forKey: Key.haptics) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.haptics) }
}
/// Experiment: an emoji key whose panel suggests emoji for what you just typed, from
/// what the words mean and what you use. Off by default.
var emoji: Bool {
get { defaults?.bool(forKey: Key.emoji) ?? false }
nonmutating set { defaults?.set(newValue, forKey: Key.emoji) }
}
/// Simulator scenes pass `--experiment-full-keyboard` or `--keyboard full|dictation-bar`
/// to pick the keyboard, and `--experiment-emoji` to turn the emoji experiment on.
func applyLaunchArguments(_ arguments: [String] = ProcessInfo.processInfo.arguments) {
if arguments.contains(Self.launchArgument) {
isEnabled = true
}
if let index = arguments.firstIndex(of: Self.keyboardLaunchArgument), index + 1 < arguments.count {
switch arguments[index + 1] {
case "full": isEnabled = true
case "dictation-bar": isEnabled = false
default: break
}
}
if arguments.contains(Self.emojiLaunchArgument) {
emoji = true
}
}
}