mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
TestFlight (build 56, iPhone 17 Pro, iOS 27.2.1, English, Auto-capitalization,
Autocorrect and Spatial autocorrect on): "Getting random words capitalized".
The screenshot reads "Testing how this World" with "working | Works | writing"
in the strip.
Cause, reproduced on build 56 (2ef08aa4) on a Mac Studio simulator (iPhone 17
Pro, iOS 27.2, real HID touches and swipes): Swipe typing read your own
UILexicon words with their capitals. With "World" and "Works" as lexicon terms
(text replacements whose phrase is the word, which load as Contacts names do),
swiping "works" after "testing how this" typed "Works" with "World" in the
strip, and "hello world", "i will", "ask mark", "pay the bill", "a rose"
swiped as "World", "Will", "Mark", "Bill", "Rose". Typed words were already
right on build 56.
origin/dev already fixes that report with Auto-capitalization on (#2173,
withoutStrayCapital): the same build-56 cases swipe in lowercase on dev, and
typed words, completions, Spatial readings and space's fixes keep no stray
capital. Two paths were left:
- Auto-capitalization off: swipeCased and the strip kept any "own spelling"
as stored, so a Contacts name or learned fix that is also a common word
still went in capitalised ("testing how this Works i Will" on dev).
isOwnSpelling now only counts a capital withoutStrayCapital would keep;
text replacement phrases still count as stored.
- Your vocabulary (#2205): withoutStrayCapital lowercased a vocabulary word
the dictionary knows in lowercase ("Swift" swiped or completed as "swift",
while space wrote "Swift"). A word in your vocabulary, spelled as added
(isVocabularySpelling), now keeps its capitals in every path.
Unchanged: sentence starts and auto-shift, a capital you typed, "I" and its
contractions, names the dictionary knows only capitalised ("Kate", "June",
"Monday" on space, #2091), German nouns and text replacements.
Apple's keyboard (black box, same simulator): typed and swiped "works",
"world", "will", "mark", "may", "bill", "rose", "bell" stay lowercase
mid-sentence, including with "World", "Works", "Will" and "Bill" as lexicon
terms; "june", "monday" and "kate" become "June", "Monday", "Kate" on space.
Verified:
- xcodebuild test, HEXMobile scheme, iPhone 17 Pro simulator (iOS 27.2):
621 tests, 1 skipped, 0 failures, with new
AutocorrectEngineTests.testYourCommonWordsStayLowercaseAndYourVocabularyKeepsItsCapitals
and FullKeyboardEngineTests.testSwipedCommonWordsStayLowercaseMidSentenceAndVocabularyKeepsItsCapitals.
- Live, this branch in a hosted field with the same lexicon: with
Auto-capitalization off, "testing how this works i will hello world"
swiped all lowercase (strip lowercase too); with it on, 12 swiped and 13
typed phrases match Apple's casing, sentence starts capitalised.
45 lines
2.1 KiB
Swift
45 lines
2.1 KiB
Swift
import Foundation
|
|
|
|
/// Hex's vocabulary list (`CustomVocabularySettings.terms`) as the keys use it: programmer
|
|
/// slang, names and other words the dictionary doesn't know are kept as typed, spelled your
|
|
/// way ("github" -> "GitHub"), completed in the strip and read by Swipe typing.
|
|
@MainActor
|
|
extension AutocorrectEngine {
|
|
/// The words your vocabulary adds to your own: each term, and each word of a phrase.
|
|
static func vocabularyWords(_ terms: [String]) -> [String] {
|
|
var words: [String] = []
|
|
for term in terms {
|
|
words.append(term)
|
|
if term.contains(" ") { words += term.split(separator: " ").map(String.init) }
|
|
}
|
|
return words
|
|
}
|
|
|
|
/// The vocabulary word `token` spells, whatever its capitals; nil when it isn't one.
|
|
func vocabularyTerm(for token: String) -> String? {
|
|
guard !vocabulary.isEmpty else { return nil }
|
|
return Self.vocabularyWords(vocabulary).first { $0.caseInsensitiveCompare(token) == .orderedSame }
|
|
}
|
|
|
|
/// Whether `word` is in your vocabulary spelled exactly so, capitals and all: it keeps
|
|
/// them anywhere in a sentence, as you added it.
|
|
func isVocabularySpelling(_ word: String) -> Bool {
|
|
!vocabulary.isEmpty && Self.vocabularyWords(vocabulary).contains(word)
|
|
}
|
|
|
|
/// What space puts in for `token`, a vocabulary word: your spelling, with a capital you
|
|
/// typed first ("github" -> "GitHub", "Kubectl" stays); nil when that is what you typed.
|
|
static func vocabularySpelling(of token: String, as term: String) -> String? {
|
|
let spelled = matchCase(of: token, onto: term)
|
|
return spelled == token ? nil : spelled
|
|
}
|
|
|
|
/// Your vocabulary's first term that starts with `token` (two letters or more) and is
|
|
/// longer, cased as `token` starts.
|
|
func vocabularyCompletion(for token: String) -> String? {
|
|
guard token.count >= 2, !vocabulary.isEmpty else { return nil }
|
|
let lower = token.lowercased()
|
|
guard let term = vocabulary.first(where: { $0.count > token.count && $0.lowercased().hasPrefix(lower) }) else { return nil }
|
|
return Self.matchCase(of: token, onto: term)
|
|
}
|
|
}
|