mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
TestFlight testers (builds 54/55) asked to turn off the capital at the start
of their typing ("you can lowercase everything on dictation but not regular
keyboard"). Settings › Keyboard gains Auto-capitalization, above Autocorrect,
on by default, as Apple's switch of the same name
(FullKeyboardSettings.autoCapitalization, App Group key
settings.keyboardAutoCapitalization; "Capitalizes the start of sentences",
zh-Hans 自动大写 / 句首字母自动大写).
Off, Hex adds no capital you didn't type, matching Apple's keyboard with
Auto-Capitalization off on the iOS 27.2 simulator ("hello world. i am mary.
im here. monday" -> "hello world. i am mary. i'm here. monday"; "^hi i speak
englsh on mondya with ^mary" -> "Hi i speak english on monday with Mary"):
- Shift never turns itself on, whatever the field's autocapitalizationType
(sentences, words, allCharacters): not at a field's or sentence's start,
after "." "!" "?", or after the double-space period (which still types
". "). FullKeyboardEngine.autoCapitalizes maps the mode to .none.
- Autocorrect (AutocorrectEngine.addsCapitals, passed to bilingual
autocorrect's partner): English fixes, Spatial readings and UITextChecker
guesses keep the case you typed ("i" stays, "im" -> "i'm", "mondya" ->
"monday"); a fix that would only add a capital ("i" -> "I") isn't made.
#2091's lowercase-name capitalisation ("mary" -> "Mary") is skipped.
- Swipe typing (#2106): no sentence-start capital from the space it adds,
and no name capital; readings come out lowercase.
Kept: capitals you typed (shift, caps lock, "Teh" -> "The", "Im" -> "I'm"),
and your own spellings: text replacements, Contacts names and other UILexicon
terms, words you kept, fixes Hex learned (isOwnSpelling). The strip still
offers capitalised words to pick. On, nothing changes.
Dictation is separate: Settings › Dictation › Lowercase (#2103) is untouched.
Verified on an iPhone 17 simulator (iOS 27.2), Mac Studio:
- xcodebuild test: 365 tests, 0 failures, 1 skipped (needs
HEX_SPEECH_CLIPS), including the new cases in FullKeyboardEngineTests
(shift never turns on in any mode, shift and caps lock work, switching
back on capitalises; a swiped word after "Great." stays lowercase) and
AutocorrectEngineTests (fixes add no capitals; Spatial keeps "mary" and
"monday" lowercase and a Contacts name's capital).
- The Settings switch, tapped, stored false in the App Group.
- Live in Messages with Hex's keyboard, off: an empty message showed
lowercase keys; "hello world. i think im here. mary is here! ok" typed as
"hello world. i think i'm here. mary is here! ok", and shift then "ok"
gave "Ok". On: "Hello world. I think I'm here. Mary is here! Ok", as before.
- Settings › Keyboard rendered in English and Simplified Chinese.
456 lines
19 KiB
Swift
456 lines
19 KiB
Swift
import SwiftUI
|
||
|
||
/// Settings › Dictation: how Hex writes what you say, and the microphone.
|
||
struct DictationSettingsPage: View {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@Bindable var dictation: DictationController
|
||
@State private var cleanupTagger = CleanupTaggerSettings().isEnabled
|
||
@State private var customVocabulary = CustomVocabularySettings().isEnabled
|
||
@State private var lowercase = DictationLowercaseSettings().isEnabled
|
||
|
||
var body: some View {
|
||
SettingsPageScaffold(title: "Dictation") {
|
||
SettingsCard {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Style"))
|
||
Spacer(minLength: 8)
|
||
Menu {
|
||
ForEach(DictationStyle.allCases, id: \.self) { candidate in
|
||
Button {
|
||
dictation.setStyle(candidate)
|
||
} label: {
|
||
if dictation.style == candidate {
|
||
Label(candidate.label, systemImage: "checkmark")
|
||
} else {
|
||
Text(candidate.label)
|
||
}
|
||
}
|
||
}
|
||
} label: {
|
||
SettingsMenuValue(value: dictation.style.label)
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 48)
|
||
|
||
SettingsDivider()
|
||
|
||
// After the style, on every path (`DictationPipeline`).
|
||
SettingsToggleRow(
|
||
title: String(localized: "Lowercase"),
|
||
detail: String(localized: "Lowercases everything"),
|
||
isOn: $lowercase
|
||
)
|
||
|
||
DictationLanguageRow(dictation: dictation)
|
||
}
|
||
|
||
SettingsCard {
|
||
TranslateDictationRow()
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Clean up what I say"),
|
||
detail: String(localized: "Drops ums, repeats and corrected words"),
|
||
isOn: $cleanupTagger
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Custom vocabulary"),
|
||
detail: String(localized: "Spell names and terms your way"),
|
||
isOn: $customVocabulary
|
||
)
|
||
|
||
if customVocabulary {
|
||
CustomVocabularyEditor()
|
||
.padding(.horizontal, 16)
|
||
.padding(.top, 2)
|
||
.padding(.bottom, 14)
|
||
}
|
||
}
|
||
|
||
SettingsCard {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Keep mic warm"))
|
||
Spacer(minLength: 8)
|
||
SettingsSegments(
|
||
items: WarmSessionDuration.allCases,
|
||
selected: dictation.warmDuration,
|
||
label: \.shortLabel,
|
||
onSelect: { duration in
|
||
withAnimation(HexMotion.settleAnimation(reduceMotion: reduceMotion)) {
|
||
dictation.selectWarmDuration(duration)
|
||
}
|
||
}
|
||
)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 50)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Always use iPhone microphone"),
|
||
detail: String(localized: "Keeps music playing and starts faster"),
|
||
isOn: Binding(
|
||
get: { !dictation.allowBluetoothMic },
|
||
set: { dictation.setAllowBluetoothMic(!$0) }
|
||
)
|
||
)
|
||
}
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: customVocabulary)
|
||
.onChange(of: cleanupTagger) { _, enabled in
|
||
CleanupTaggerSettings().isEnabled = enabled
|
||
}
|
||
.onChange(of: customVocabulary) { _, enabled in
|
||
CustomVocabularySettings().isEnabled = enabled
|
||
}
|
||
.onChange(of: lowercase) { _, enabled in
|
||
DictationLowercaseSettings().isEnabled = enabled
|
||
}
|
||
.onAppear {
|
||
cleanupTagger = CleanupTaggerSettings().isEnabled
|
||
customVocabulary = CustomVocabularySettings().isEnabled
|
||
lowercase = DictationLowercaseSettings().isEnabled
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Which keyboard Hex shows: the full keyboard (letters, with a Hex key to dictate) or the
|
||
/// dictation bar. Stored as `FullKeyboardSettings.isEnabled`.
|
||
private enum KeyboardChoice: CaseIterable {
|
||
case full
|
||
case dictationBar
|
||
|
||
var label: String {
|
||
switch self {
|
||
case .full: String(localized: "Full")
|
||
case .dictationBar: String(localized: "Dictation bar")
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Settings › Keyboard: Full or Dictation bar, the full keyboard's rows (only while it's
|
||
/// chosen; Auto-capitalization, on by default as Apple's, sits above Autocorrect; Spatial autocorrect only while Autocorrect is on, and Suggest swear words off by
|
||
/// default, as Apple's keyboard never offers them), and haptics, which the dictation bar uses
|
||
/// too.
|
||
struct KeyboardSettingsPage: View {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@State private var fullKeyboard = FullKeyboardSettings().isEnabled
|
||
@State private var autoCapitalization = FullKeyboardSettings().autoCapitalization
|
||
@State private var autocorrect = FullKeyboardSettings().autocorrect
|
||
@State private var spatialAutocorrect = FullKeyboardSettings().spatialAutocorrect
|
||
@State private var suggestSwearWords = FullKeyboardSettings().suggestSwearWords
|
||
@State private var keyPopups = FullKeyboardSettings().keyPopups
|
||
@State private var haptics = FullKeyboardSettings().haptics
|
||
@State private var practiceText = ""
|
||
|
||
var body: some View {
|
||
SettingsPageScaffold(title: "Keyboard") {
|
||
SettingsCard {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(title: String(localized: "Keyboard"))
|
||
Spacer(minLength: 8)
|
||
SettingsSegments(
|
||
items: KeyboardChoice.allCases,
|
||
selected: fullKeyboard ? .full : .dictationBar,
|
||
label: \.label,
|
||
onSelect: { choice in
|
||
fullKeyboard = choice == .full
|
||
}
|
||
)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 50)
|
||
|
||
if fullKeyboard {
|
||
KeyboardLanguagesRow()
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Auto-capitalization"),
|
||
detail: String(localized: "Capitalizes the start of sentences"),
|
||
isOn: $autoCapitalization
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Autocorrect"),
|
||
detail: String(localized: "Fixes typos when you press space"),
|
||
isOn: $autocorrect
|
||
)
|
||
|
||
if autocorrect {
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Spatial autocorrect"),
|
||
detail: String(localized: "Uses where you tap, in English and Spanish"),
|
||
isOn: $spatialAutocorrect
|
||
)
|
||
}
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Suggest swear words"),
|
||
detail: String(localized: "Slurs are never suggested"),
|
||
isOn: $suggestSwearWords
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Key pop-ups"),
|
||
detail: String(localized: "Shows the letter above your finger"),
|
||
isOn: $keyPopups
|
||
)
|
||
}
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Haptics"),
|
||
detail: String(localized: "A light tap as you press Hex's keys"),
|
||
isOn: $haptics
|
||
)
|
||
}
|
||
|
||
TextField("Test keyboard…", text: $practiceText, axis: .vertical)
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.lineLimit(1...4)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 13)
|
||
.background(
|
||
HexTheme.bgBase,
|
||
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
||
)
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: fullKeyboard)
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: autocorrect)
|
||
.onChange(of: fullKeyboard) { _, enabled in
|
||
FullKeyboardSettings().isEnabled = enabled
|
||
}
|
||
.onChange(of: autoCapitalization) { _, enabled in
|
||
FullKeyboardSettings().autoCapitalization = enabled
|
||
}
|
||
.onChange(of: autocorrect) { _, enabled in
|
||
FullKeyboardSettings().autocorrect = enabled
|
||
}
|
||
.onChange(of: spatialAutocorrect) { _, enabled in
|
||
FullKeyboardSettings().spatialAutocorrect = enabled
|
||
}
|
||
.onChange(of: suggestSwearWords) { _, enabled in
|
||
FullKeyboardSettings().suggestSwearWords = enabled
|
||
}
|
||
.onChange(of: keyPopups) { _, enabled in
|
||
FullKeyboardSettings().keyPopups = enabled
|
||
}
|
||
.onChange(of: haptics) { _, enabled in
|
||
FullKeyboardSettings().haptics = enabled
|
||
}
|
||
.onAppear {
|
||
fullKeyboard = FullKeyboardSettings().isEnabled
|
||
autoCapitalization = FullKeyboardSettings().autoCapitalization
|
||
autocorrect = FullKeyboardSettings().autocorrect
|
||
spatialAutocorrect = FullKeyboardSettings().spatialAutocorrect
|
||
suggestSwearWords = FullKeyboardSettings().suggestSwearWords
|
||
keyPopups = FullKeyboardSettings().keyPopups
|
||
haptics = FullKeyboardSettings().haptics
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Settings › Privacy: what Hex keeps about how you type, all of it on this iPhone, and
|
||
/// under Advanced the typing logs you can record to export.
|
||
struct PrivacySettingsPage: View {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@State private var learnTyping = TypingJournalSettings().isEnabled
|
||
@State private var typingLogs = TypingLogSettings().isEnabled
|
||
@State private var showTypingLogs = false
|
||
@State private var confirmingTypingLogs = SettingsSnapshotFixture.confirmsTypingLogs
|
||
|
||
var body: some View {
|
||
SettingsPageScaffold(title: "Privacy") {
|
||
HStack(spacing: 7) {
|
||
Image(systemName: "lock.fill")
|
||
.font(.system(size: 11, weight: .medium))
|
||
Text("Everything stays on this iPhone")
|
||
.font(.system(size: 13))
|
||
}
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.padding(.horizontal, 16)
|
||
.padding(.bottom, 2)
|
||
|
||
SettingsCard {
|
||
// Not only for the full keyboard: it also learns from dictations the
|
||
// dictation bar inserts.
|
||
SettingsToggleRow(
|
||
title: String(localized: "Learn how I type"),
|
||
detail: String(localized: "Learns from taps and the words you fix"),
|
||
isOn: $learnTyping
|
||
)
|
||
|
||
if learnTyping {
|
||
SettingsDivider()
|
||
TypingInsightsView()
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 12)
|
||
}
|
||
}
|
||
|
||
SettingsSectionHeader(title: "Advanced")
|
||
|
||
SettingsCard {
|
||
// Apart from Learn how I type: this keeps everything, to export and train on.
|
||
// Turning it on asks first (App Review 2.5.14); turning it off doesn't.
|
||
SettingsToggleRow(
|
||
title: String(localized: "Record typing logs"),
|
||
detail: String(localized: "Records taps and the text you type for 14 days, on this iPhone, to export. Off by default."),
|
||
isOn: Binding(
|
||
get: { typingLogs },
|
||
set: { on in
|
||
if on {
|
||
confirmingTypingLogs = true
|
||
} else {
|
||
typingLogs = false
|
||
}
|
||
}
|
||
)
|
||
)
|
||
.alert("Record typing logs?", isPresented: $confirmingTypingLogs) {
|
||
Button("Cancel", role: .cancel) {}
|
||
Button("Turn On") {
|
||
typingLogs = true
|
||
}
|
||
} message: {
|
||
Text("Hex's keyboard will record each tap and the text you type or dictate with it, including the text around the cursor, for 14 days. The logs stay on this iPhone for you to export or delete. Password, code and card fields are never recorded.")
|
||
}
|
||
|
||
if typingLogs {
|
||
SettingsDivider()
|
||
Button {
|
||
showTypingLogs = true
|
||
} label: {
|
||
SettingsLinkLabel(title: String(localized: "Typing logs"))
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: learnTyping)
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: typingLogs)
|
||
.sheet(isPresented: $showTypingLogs) {
|
||
TypingLogsView()
|
||
}
|
||
.onChange(of: learnTyping) { _, enabled in
|
||
TypingJournalSettings().isEnabled = enabled
|
||
}
|
||
.onChange(of: typingLogs) { _, enabled in
|
||
TypingLogSettings().isEnabled = enabled
|
||
}
|
||
.onAppear {
|
||
learnTyping = TypingJournalSettings().isEnabled
|
||
typingLogs = TypingLogSettings().isEnabled
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Settings › Experiments: unfinished features, off until turned on. They live in the App
|
||
/// Group so the keyboard reads them too.
|
||
struct ExperimentsSettingsPage: View {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@State private var emoji = FullKeyboardSettings().emoji
|
||
@State private var emojiHistoryEmpty = EmojiUsageStore().isEmpty
|
||
@State private var swipeTyping = FullKeyboardSettings().swipeTyping
|
||
@State private var appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
|
||
@State private var cleanupAvailability = AppleIntelligenceCleanupAvailability.current
|
||
|
||
var body: some View {
|
||
SettingsPageScaffold(title: "Experiments") {
|
||
SettingsCard {
|
||
EmojiExperimentRows(emoji: $emoji, historyEmpty: $emojiHistoryEmpty)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Swipe typing"),
|
||
detail: FullKeyboardSettings().isEnabled
|
||
? String(localized: "Slide across a word's letters, in English and Spanish")
|
||
: String(localized: "Needs the full keyboard"),
|
||
isOn: $swipeTyping
|
||
)
|
||
|
||
SettingsDivider()
|
||
|
||
SettingsToggleRow(
|
||
title: String(localized: "Clean up with Apple Intelligence"),
|
||
detail: cleanupAvailability.reason ?? String(localized: "Fixes misheard words on device"),
|
||
isOn: $appleIntelligenceCleanup
|
||
)
|
||
.disabled(!cleanupAvailability.isAvailable)
|
||
}
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: emoji)
|
||
.onChange(of: appleIntelligenceCleanup) { _, enabled in
|
||
AppleIntelligenceCleanupSettings().isEnabled = enabled
|
||
}
|
||
.onChange(of: swipeTyping) { _, enabled in
|
||
FullKeyboardSettings().swipeTyping = enabled
|
||
}
|
||
.onAppear {
|
||
emoji = FullKeyboardSettings().emoji
|
||
swipeTyping = FullKeyboardSettings().swipeTyping
|
||
emojiHistoryEmpty = EmojiUsageStore().isEmpty
|
||
appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
|
||
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Experiments › Emoji: the full keyboard's emoji key, and while it's on, Clear emoji history.
|
||
private struct EmojiExperimentRows: View {
|
||
@Binding var emoji: Bool
|
||
@Binding var historyEmpty: Bool
|
||
|
||
var body: some View {
|
||
SettingsToggleRow(
|
||
title: String(localized: "Emoji"),
|
||
detail: FullKeyboardSettings().isEnabled
|
||
? String(localized: "An emoji key with suggestions as you type")
|
||
: String(localized: "Needs the full keyboard"),
|
||
isOn: $emoji
|
||
)
|
||
.onChange(of: emoji) { _, enabled in
|
||
FullKeyboardSettings().emoji = enabled
|
||
}
|
||
|
||
if emoji {
|
||
SettingsDivider()
|
||
Button {
|
||
EmojiUsageStore().clear()
|
||
historyEmpty = true
|
||
} label: {
|
||
Text("Clear emoji history")
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(historyEmpty ? HexTheme.textFaint : HexTheme.textBase)
|
||
.frame(maxWidth: .infinity, minHeight: 50, alignment: .leading)
|
||
.padding(.horizontal, 16)
|
||
.contentShape(Rectangle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
.disabled(historyEmpty)
|
||
}
|
||
}
|
||
}
|