hex/ios/HEXShared/FullKeyboard/CzechTyping.swift
Ryan Vogel bc8adad220 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).
2026-11-21 10:23:18 -05:00

67 lines
2.9 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 Czech layout's ´ and ˇ keys, as the system Czech keyboard was observed to apply them
/// (iOS 27.2 simulator, real touches in Messages, every letter followed by each key, black box).
/// Neither is a dead key: each accents the letter right before it, as Greek's tonos key does,
/// and after anything else (another letter, an accented one, a space, nothing) types itself.
/// ´ gives á ć é í ĺ ń ó ŕ ś ú ý ź; ˇ gives č ď ě ľ ň ř š ť ž, and ů after u; the ring ˚, held on
/// ˇ, gives ů and å. Capitals take theirs (Á, Č, Ů). Delete takes the accented letter whole.
nonisolated enum CzechTyping {
static let acuteKey = "\u{00B4}"
static let caronKey = "\u{02C7}"
static let ringKey = "\u{02DA}"
private static let marks: [String: [Character: Character]] = [
acuteKey: [
"a": "á", "c": "ć", "e": "é", "i": "í", "l": "ĺ", "n": "ń", "o": "ó", "r": "ŕ", "s": "ś",
"u": "ú", "y": "ý", "z": "ź",
],
caronKey: [
"c": "č", "d": "ď", "e": "ě", "l": "ľ", "n": "ň", "r": "ř", "s": "š", "t": "ť", "z": "ž",
"u": "ů",
],
ringKey: ["a": "å", "u": "ů"],
]
/// The letter `before` ends with, accented by the mark `text` types after it; nil when
/// the key types the mark itself.
static func accenting(_ text: String, after before: String?) -> String? {
guard let table = marks[text], let last = before?.last else { return nil }
let lower = Character(last.lowercased())
guard let accented = table[lower] else { return nil }
return last.isUppercase ? accented.uppercased() : String(accented)
}
}
@MainActor
extension FullKeyboardEngine {
/// The layout's own keys' typing rules: Greek's tonos key and final sigma (`GreekTyping`),
/// Czech's ´ and ˇ (`CzechTyping`). True when the key already did all it does; else
/// `text` is what to type.
func typeLayoutRules(_ text: inout String) -> Bool {
switch layout.language {
case .greek: typeGreek(&text)
case .czech: typeCzech(text)
default: false
}
}
/// Czech: a held ˇ's ˇ or ˚ accents the letter before it, as a tapped ˇ does. True when it
/// did; else the held key's choice goes in as it is.
func typeHeldMark(_ chosen: String) -> Bool {
guard layout.language == .czech else { return false }
var mark = chosen
return typeLayoutRules(&mark)
}
/// ´, ˇ or ˚ after a letter it accents: puts the accented letter in its place. False
/// otherwise, and the mark is typed as itself.
private func typeCzech(_ text: String) -> Bool {
guard let accented = CzechTyping.accenting(text, after: target.documentContextBeforeInput) else { return false }
target.deleteBackward()
target.insertText(accented)
didEdit()
logState("typed")
return true
}
}