mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
* iOS: Czech keyboard, ´ and ˇ keys, diacritic autocorrect, and the strip keeps to the sentence's language
A TestFlight tester (build 56, iPhone 17 Pro Max): "I use Czech and English
languages. But it isn't easy to switch between the languages, and
autocomplete suggests English words in Czech too."
Adds KeyboardLanguage.czech ("cs", Čeština), as Polish (#2143) and Greek
(#2184) were added. It matches the standard Czech layout and the system
keyboard's observed long-press options, as the iOS 27.2 simulator's own Czech
keyboard shows them (every letter, 123 and #+= key held for about 3 s with a
real touch, the callout read from the accessibility tree, the
keyboard-provenance survey and converter as since #2140; screenshots checked):
- Rows ("QWERTZ – Czech/Slovak", Apple's default): qwertzuiop / asdfghjkl´ /
yxcvbnmˇ. Rows 1 and 2 are ten keys edge to edge, row 3 starts under s, and
shift and delete are a letter wide.
- Layouts (#2172): Apple's Add New Keyboard › Czech offers only "QWERTZ –
Czech/Slovak" and "QWERTY – Czech/Slovak" (read through accessibility), so
Czech offers .own ("QWERTZ – Čeština") and .qwerty ("QWERTY – Čeština"),
which is its own rows with Z and Y swapped, both keys kept, as the system
QWERTY variant's keys read.
- The ´ (U+00B4) and ˇ (U+02C7) keys are not dead keys. Observed in Messages
with real touches, every letter followed by each key: each accents the
letter right before it, ´ -> á ć é í ĺ ń ó ŕ ś ú ý ź, ˇ -> č ď ě ľ ň ř š ť ž
and ů after u; capitals too (A´ -> Á, Cˇ -> Č); after anything else (aˇ,
x´, á´, a space, nothing) the key types itself; delete then removes the
accented letter whole. A held ˇ offers ˚, which makes ů and å. CzechTyping
holds these rules; FullKeyboardEngine dispatches Greek's and Czech's
through typeLayoutRules (the file stays under the 1,500-line cap).
- letterHolds: e ě é ê è ę ë ē ė; r ř ŕ; t ť; z ż ź ž; u ú ů û ü ù ū;
i í î ï ì į ī; o ó ô ö ò õ œ ø ō; a á à ą â ä æ ã å ā; s š ß ś; d ď;
l ł ľ ĺ; y ý ÿ; c č ç ć; n ň ñ ń; ˇ ˚. Nothing on ´ or any other key.
Callouts are laid out as the system's (AccentCatalog.arrangement, e.g.
ě e é …). 123/#+= pages and every symbol hold are English's (& § read too).
Autocorrect uses iOS's cs dictionary through the dictionary engine (no typing
model). Missing háčky and čárky are the cheapest fix, however many, as Polish
diacritics are (0.15 plus 0.05 each further one): "cesky" -> "český",
"prilis" -> "příliš". Czech has Latin letters, so it pairs with English for
bilingual autocorrect (#2186), and #2143's any-word partner guard applies.
cs/cs-CZ picks the layout automatically, the space bar says "Čeština", Hex's
next-word lists get Czech entries, and snapshot scenes take
--keyboard-layout cs.
Sentence language in the strip: with two languages the strip interleaved
both languages' candidates whatever the words before were, so a Czech
sentence always showed an English word in a slot. Now a sentence that leans
one language (languageLean, as autocorrect already uses) gets only that
language's candidates, even where it has none: live in Messages, the
simulator's Czech dictionary completed nothing for "ku" after "Příliš
žluťoučký", and English filled the strip with "kurtosis" and "kudos". With no
words before, both languages' in turn, as before. Autocorrect itself is unchanged (#2186: an
English typo in a mixed French sentence is still fixed; a stricter rule broke
testTheFrenchKeyboardFixesEnglishTyposWithEnglishBesideIt, so it was dropped).
Dictation: cs-CZ goes through Apple Speech, never Parakeet (English-only).
macOS 27.2.1 lists cs-CZ for DictationTranscriber only; say -v Zuzana clips
came back with every háček and čárka, numbers as digits ("10 min.", "19:30")
and no punctuation. Dictation follows the keyboard's language (#2164), and
Apple's Settings offers "Add to English (US) Keyboard" for Czech, as for
French; Hex keeps Czech on its own keys beside English, as it does French.
Live (iPhone 17 Pro simulator, Hex's keyboard in Messages, real HID touches):
typed "Příliš žluťoučký kůň" with ´, ˇ and a held ˚.
Verified (iPhone 17 Pro simulator, iOS 27.2, Mac Studio): KeyboardLayoutTests,
FullKeyboardEngineTests, AutocorrectEngineTests, DictationControllerTests and
TranscriptCleanupTests pass (with new Czech cases: rows, layouts, holds,
arrangements, automatic pick, partner, typing "Příliš žluťoučký kůň" through
´ ˇ and a held ˚, the marks' fallbacks, capitals and delete, missing-diacritic
fixes on a stub dictionary, the strip's language order, cs-CZ from
DictationTranscriber, Polished/Casual/Lowercase), and the full HEXMobile
suite passes with the custom-words change on top, rebased on origin/dev
68f18a3b (619 tests, 1 skipped, 0 failures). Rebased onto #2192 (no
clearPendingUndo before a mark's accent, as GreekTyping) and #2199 (Czech's
inputModeLanguage is cs-CZ).
* iOS: Hex's vocabulary reaches the keyboard, Add to vocabulary from the strip, and no added capitals in the strip
A TestFlight tester (build 56): "Feat req: custom dictionary for uncommon
programmer slang. Also, even with auto-capitalization off, many suggested
words are capitalized."
What reached the full keyboard before: iOS's text replacements and Contacts
names (requestSupplementaryLexicon -> loadLexicon: a replacement whose phrase
is its shortcut counts as a word). Hex's own custom vocabulary
(CustomVocabularySettings, Settings › Dictation) was dictation only; nothing
in the keys read it.
Custom words (AutocorrectEngine+Vocabulary, setVocabulary):
- The keyboard reads CustomVocabularySettings.terms (the one list dictation
spells with), whether or not dictation's switch is on, at open and on each
settings sync; a bilingual partner gets the same list.
- Its words, and each word of a phrase, join your own words (lexiconTerms):
never autocorrected away, no spelling guesses for them, a different case
put right on space ("github" -> "GitHub"), completed in the strip before
the dictionary's words ("kub" -> "kubectl"), and Swipe typing reads them
(ownWords) and the Spatial decoder (userWords) knows them.
- Settings › Keyboard › Vocabulary (with the full keyboard): how many words,
and a page with the same editor as Dictation's, its footer saying how to
add from the keys. Dictation's editor is unchanged.
- In the keys: hold the strip's left slot (the word you typed) and the strip
offers "Add to vocabulary" in the notice shape (title, "Never
autocorrected", chip). The chip saves it to the App Group and uses it at
once; typing dismisses it. A capital only the sentence's start gave the
word ("Nginx" opening a message) is left out. Without Full Access the
keyboard can't write the App Group, so the word lasts the session.
- New strings with zh-Hans: Vocabulary, its row's two details (one plural),
the page footer, Add to vocabulary, Never autocorrected.
Capitals with Auto-capitalization off, checked on origin/dev (a0a7da5e) with
a throwaway test: autocorrect itself was right (#2173: "mondy" -> "monday"),
but the strip still offered "Mandy" (a guess iOS knows capitalised), "I'd"
for "id" (suggest-only contractions), and "Monday" as a completion of "mon".
Now, with it off and nothing typed in capitals, the strip lowercases every
candidate that isn't your own spelling (a vocabulary word, Contacts name,
text replacement, kept word or learned fix), and drops one that becomes what
you typed. Unchanged: sentence and clause starters, which keep "I" and "I'm"
(#2135, testSentenceStartersAndNextWordsFillAllThreeSlots), next words (the
model is lowercase), swipe readings (#2173's swipeCased), and a capital you
typed. AutocorrectEngine stays under the 1,500-line cap: the strip rule,
withoutStrayCapital and previousWord moved, unchanged, to the case-matching
file (AutocorrectEngine+Distance).
Verified (iPhone 17 Pro simulator, iOS 27.2, Mac Studio):
- Full HEXMobile suite, rebased on origin/dev 68f18a3b: 619 tests, 1
skipped, 0 failures, with new
AutocorrectEngineTests.testVocabularyWordsAreKeptSpelledYourWayAndCompleted,
testAutoCapitalizationOffSuggestsNoCapitals and
FullKeyboardEngineTests.testSwipeTypesYourVocabularyWords ("kubectl" isn't
swiped before it is in the list, is after).
- Live, Hex's keyboard in Messages with real touches: typed "Nginx" at a
message's start, held the left slot ("nginx" offered), tapped Add to
vocabulary (the App Group then held "nginx" in customVocabulary.terms);
"ngi" then offered "nginx" in the strip, picked it, and "nginx " stayed as
typed. The same with "kubectl" before the rebase.
Settings › Keyboard showed "Vocabulary, 3 words autocorrect keeps and
suggests" and its page, in English and zh-Hans.
176 lines
6.2 KiB
Swift
176 lines
6.2 KiB
Swift
import SwiftUI
|
||
|
||
/// The custom vocabulary list shown under its switch in Settings › Dictation, and on
|
||
/// Settings › Keyboard › Vocabulary: one list, which dictation spells (with its switch on) and
|
||
/// the full keyboard never autocorrects away, completes and swipes.
|
||
struct CustomVocabularyEditor: View {
|
||
private let settings = CustomVocabularySettings()
|
||
var footer = String(localized: "Fixes spelling, not words Hex mishears")
|
||
|
||
@State private var terms: [String] = []
|
||
@State private var draft = ""
|
||
@State private var notice: String?
|
||
|
||
private var isAtLimit: Bool {
|
||
terms.count >= CustomVocabularySettings.maxTermCount
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
ForEach(terms, id: \.self) { term in
|
||
HStack(spacing: 10) {
|
||
Text(term)
|
||
.font(.system(size: 14))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.lineLimit(1)
|
||
|
||
Spacer(minLength: 8)
|
||
|
||
Button {
|
||
remove(term)
|
||
} label: {
|
||
Image(systemName: "xmark")
|
||
.font(.system(size: 11, weight: .semibold))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.frame(width: 26, height: 26)
|
||
.background(HexTheme.layer02, in: Circle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
.accessibilityLabel("Remove \(term)")
|
||
}
|
||
.padding(.leading, 12)
|
||
.padding(.trailing, 6)
|
||
.frame(minHeight: 36)
|
||
.background(
|
||
HexTheme.layer01,
|
||
in: RoundedRectangle(
|
||
cornerRadius: HexTheme.controlRadius,
|
||
style: .continuous
|
||
)
|
||
)
|
||
}
|
||
|
||
TextField("Add a word or phrase", text: $draft)
|
||
.font(.system(size: 14))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.textInputAutocapitalization(.never)
|
||
.autocorrectionDisabled()
|
||
.submitLabel(.done)
|
||
.onSubmit(add)
|
||
.onChange(of: draft) { _, _ in
|
||
notice = nil
|
||
}
|
||
.disabled(isAtLimit)
|
||
.padding(.horizontal, 12)
|
||
.frame(minHeight: 38)
|
||
.background(
|
||
HexTheme.layer01,
|
||
in: RoundedRectangle(
|
||
cornerRadius: HexTheme.controlRadius,
|
||
style: .continuous
|
||
)
|
||
)
|
||
.opacity(isAtLimit ? 0.5 : 1)
|
||
|
||
if isAtLimit {
|
||
Text("Up to 100 terms")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
|
||
if let notice {
|
||
Text(notice)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
|
||
Text(footer)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
.onAppear {
|
||
terms = settings.terms
|
||
}
|
||
}
|
||
|
||
private func add() {
|
||
guard !isAtLimit else { return }
|
||
let candidate = draft.trimmingCharacters(in: .whitespacesAndNewlines)
|
||
guard !candidate.isEmpty else { return }
|
||
|
||
guard candidate.count <= CustomVocabularySettings.maxTermLength else {
|
||
notice = String(localized: "Too long")
|
||
return
|
||
}
|
||
let key = VocabularySpelling.normalizedKey(candidate)
|
||
guard key.count >= 2 else {
|
||
notice = String(localized: "Needs at least two letters or digits")
|
||
return
|
||
}
|
||
let isDuplicate = terms.contains {
|
||
VocabularySpelling.normalizedKey($0) == key
|
||
}
|
||
guard !isDuplicate else {
|
||
notice = String(localized: "Already in the list")
|
||
return
|
||
}
|
||
|
||
let updated = CustomVocabularySettings.sanitize(terms + [candidate])
|
||
terms = updated
|
||
settings.terms = updated
|
||
draft = ""
|
||
notice = nil
|
||
}
|
||
|
||
private func remove(_ term: String) {
|
||
terms.removeAll { $0 == term }
|
||
settings.terms = terms
|
||
notice = nil
|
||
}
|
||
}
|
||
|
||
/// Settings › Keyboard › Vocabulary: how many words the list holds, opening its page.
|
||
struct KeyboardVocabularyRow: View {
|
||
@State private var count = CustomVocabularySettings().terms.count
|
||
@State private var showsPage = false
|
||
|
||
var body: some View {
|
||
Button {
|
||
showsPage = true
|
||
} label: {
|
||
HStack(spacing: 12) {
|
||
SettingsRowLabel(
|
||
title: String(localized: "Vocabulary"),
|
||
detail: count == 0
|
||
? String(localized: "Words autocorrect keeps and suggests")
|
||
: String(localized: "\(count) words autocorrect keeps and suggests")
|
||
)
|
||
Spacer(minLength: 8)
|
||
Image(systemName: "chevron.right")
|
||
.font(.system(size: 13, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
.contentShape(Rectangle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
.navigationDestination(isPresented: $showsPage) {
|
||
SettingsPageScaffold(title: "Vocabulary") {
|
||
SettingsCard {
|
||
CustomVocabularyEditor(
|
||
footer: String(localized: "Hold a word you typed in the keyboard's suggestions to add it. Dictation spells these too while Custom vocabulary is on.")
|
||
)
|
||
.padding(16)
|
||
}
|
||
}
|
||
}
|
||
.onAppear { count = CustomVocabularySettings().terms.count }
|
||
.onChange(of: showsPage) { _, shown in
|
||
if !shown { count = CustomVocabularySettings().terms.count }
|
||
}
|
||
}
|
||
}
|