hex/ios/HEXShared/FullKeyboard/CzechTyping.swift
Ryan Vogel 2472656e80 iOS keyboard: French AZERTY gets Apple's apostrophe key after N
What: Français (France)'s AZERTY is now Apple's "AZERTY – French", the layout
Apple lists first for France and Belgium: row 3 is W X C V B N and the
apostrophe key, seven keys a letter wide centred between shift and delete,
which keep their English size. As on Apple's, the key shows ’ right after a
letter and types the apostrophe (curled as the field curls quotes, straight
where it doesn't), and holds ' ’ ‘ `; anywhere else it shows and types ´
(U+00B4, never a dead key) and holds ´ ˋ ˆ ¨. A held choice goes in as it is.

Typing logic touched (for the Rust core move):
- FullKeyboardEngine: typeLayoutRules gets a .french case (FrenchTyping in
  CzechTyping.swift) that turns the key into ' after a letter; keycapLabel and
  displayLabel show ’ there; openAccentMenuIfEligible holds the 123 page's '
  after a letter (heldBase); textDidChange redraws the keys when the French
  key is on screen, so a cursor move updates its label.
- Decoder, AdaptiveTouch, next-letter odds, swipe typing: untouched. They read
  letters only (isLetter), so the key never enters their letter sets, and
  French has no typing model anyway.
- AutocorrectEngine: a word with an apostrophe used to be left alone in every
  language. In French only, frenchElisionFix now corrects each side of an
  elision's apostrophe: the word after it as a word of its own (l'hpmme ->
  l'homme, d'acvord -> d'accord), and a head that is no elision to the
  commonest one a key away when the dictionary rejects the whole word.
  Words the dictionary knows whole (aujourd'hui), a lone l' and other
  languages are unchanged. ownReplacement loses private for it.
- keyCoordinates: French AZERTY's row 3 offset 2.0 -> 1.5 (W now sits
  between Z and E), so the neighbouring-key cost matches the keys drawn.
- The iPad keeps its own ' and : key: padRows drops the iPhone key.

Replaced: PR #2096 left this key out ("Apple's French-only ´ key"); two
TestFlight testers (builds 120 and 122) and a post on X asked for it back.
Apple's Canadian and Swiss French default to "QWERTY – French" and "QWERTZ –
French" (the key at the end of row 2); Hex keeps those plain for now.

Verified: Apple's keyboard on iOS 27.2 simulators (iPhone 17 Pro and SE,
upright and turned) measured as a black box, Settings' layout lists read
through accessibility. Hex's keycaps fall on Apple's to the pixel in all four
(SE turned: 0.5 pt on shift/delete edges). Real HID touches on both phones:
"l'homme qu'il a vu n'est pas d'ici, c'est sûr" types right with the number
row off and on; l'hpmme, c'eat, d'acvord, n'eat are corrected; jai -> j'ai and
l' unchanged; the 123 page identical to origin/dev; a drag across row 3 types
the key under the lift, as before. xcodebuild test on origin/dev 3d834b6a plus
this change (iPhone 17 Pro, iOS 27.2): 803 tests, 0 failures, 3 skipped.
python3 scripts/code-shape.py passes.
2026-11-22 05:04:34 -05:00

100 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 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)
}
}
/// French AZERTY's apostrophe key after n, as Apple's "AZERTY – French" keyboard was observed
/// to apply it (iOS 27.2 simulator, iPhone 17 Pro and SE, real touches in a text view with smart
/// quotes on and off, black box). Right after a letter its keycap shows ’, a tap types the
/// apostrophe (’ where the field curls quotes, ' where it doesn't, as the 123 page's ' key does)
/// and a hold offers ' ’ ‘ ` (typed as they are); after anything else (a space, a digit, an
/// apostrophe, nothing) it shows ´, types ´ (U+00B4) itself, never as a dead key ("´e" stays
/// two characters), and a hold offers ´ ˋ ˆ ¨. It is no letter: the decoder, Adaptive touch,
/// next-letter odds and swipe typing read letters only, so none of them sees it.
nonisolated enum FrenchTyping {
static let key = "\u{00B4}"
/// Whether the key types the apostrophe after `before`: right after a letter.
static func typesApostrophe(after before: String?) -> Bool {
before?.last?.isLetter == true
}
}
@MainActor
extension FullKeyboardEngine {
/// The layout's own keys' typing rules: Greek's tonos key and final sigma (`GreekTyping`),
/// Czech's ´ and ˇ (`CzechTyping`), French's apostrophe key (`FrenchTyping`). 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: return typeGreek(&text)
case .czech: return typeCzech(text)
case .french:
if typesFrenchApostrophe(text) { text = "'" }
return false
default: return false
}
}
/// Whether `character` is French's apostrophe key and types the apostrophe here, right
/// after a letter (`FrenchTyping`).
func typesFrenchApostrophe(_ character: String) -> Bool {
layout.language == .french && character == FrenchTyping.key && FrenchTyping.typesApostrophe(after: typingContext)
}
/// The key a held `character` offers options for: French's apostrophe key after a letter
/// holds the 123 page's ', else itself.
func heldBase(_ character: String) -> String {
typesFrenchApostrophe(character) ? "'" : character
}
/// 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 }
rememberTypingContext(before: textBefore.map { String($0.dropLast(1)) }, inserted: accented)
target.deleteBackward()
target.insertText(accented)
didEdit()
logState("typed")
return true
}
}