mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
The phone lane's three requests for TypingConfigReview (#2529 renders it): - Keyboards, not one guessed context: - The keyboard records each letters keyboard it runs on, with the experiment on and Full Access, in typingConfig.keyboards (TypingConfigKeyboard: context plus KeyboardZoneGeometry), most recent first, at most 8, written only when the list changes. - TypingConfigReview(data:keyboards:) checks each key block against all of them: a block applies on the first keyboard it matches, a second block for that keyboard is a duplicate, and one that matches none is forAnotherKeyboard, with its differences from the nearest. - ContextCheck gains keyboardIndex, and keyboard is the matched or nearest one. Applied.blocks holds every applying block; Applied.aim and .zones are keyboard 0's. - compiled(switchedOn:) keeps every applying block, and the keyboard picks the one for its layout. - The zone compiler moved onto KeyboardZoneGeometry so recorded keyboards can be checked. KeyboardLayout.zoneMap wraps it, with the same results. - Evidence and place on every Item: list (file, keep, neverCorrectTo, fixes, dictation, keyBlocks, aim, zones), position in it, block, the file's evidence, and the cleaned text, so "Words to keep, number 6" comes from the result alone. - Cleaned text (TypingConfigText) for the note and every word, fix and dictation fix, so the sheet and the keyboard use the same strings. - Removed: controls (Cc), bidi embeddings, overrides, isolates and marks (U+202A-202E, U+2066-2069, U+200E, U+200F, U+061C), and invisible format characters (Cf: U+200B, U+2060, U+FEFF, U+00AD, ...). - ZWNJ and ZWJ are kept only between letters or marks of Arabic and Persian, Syriac, the Indic scripts, Sinhala, Myanmar and Khmer, and ZWJ between emoji. Tag characters are kept after a black flag. - Words are NFC-normalised and trimmed. A word that loses anything from inside it is skipped with the new Reason hiddenCharacters (after invalidValue in the order); one empty after cleaning is invalidValue. The note is cleaned, then cut at 280. - The reference's "Reading" and "On the phone" sections and docs/typing-configs.md say so. Verified on the Studio (iPhone 17 Pro, iOS 27.2): - FullKeyboardEngineTests: 163 of 163 pass, including two new cases in FullKeyboardEngineTests+AdaptiveTouch.swift. - Four blocks on upright and sideways keyboards: English upright and sideways apply, French is forAnotherKeyboard with differences [language, letters], a second upright block is a duplicate, compiled keeps both applying blocks, the keyboard picks each on its own layout, and recording dedupes most-recent-first. - Cleaning: an override, a zero-width space, a Latin ZWJ and a fix with an isolate are hiddenCharacters. A Persian word keeps its ZWNJ, a Devanagari conjunct its ZWJ, and a decomposed café becomes NFC. The note loses its newline and override and is cut at 280. - The first review case also checks list, position and evidence. - TypingLogTests: 12 of 12 pass.
35 lines
1.6 KiB
Swift
35 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
/// A keyboard a typing config may be for: its context (`TypingConfigFile.Context`) and the
|
|
/// geometry zones compile against. The keyboard records each one it runs on
|
|
/// (`TypingConfigSettings.keyboards`), so the app reviews a config against keyboards it can't draw.
|
|
nonisolated struct TypingConfigKeyboard: Codable, Equatable, Sendable {
|
|
var context: TypingConfigFile.Context
|
|
var geometry: KeyboardZoneGeometry
|
|
|
|
init(context: TypingConfigFile.Context, geometry: KeyboardZoneGeometry) {
|
|
self.context = context
|
|
self.geometry = geometry
|
|
}
|
|
|
|
init(layout: KeyboardLayout) {
|
|
self.init(context: TypingConfigFile.Context(layout: layout), geometry: KeyboardZoneGeometry(layout: layout))
|
|
}
|
|
}
|
|
|
|
nonisolated extension TypingConfigSettings {
|
|
/// The keyboards Hex's keys have run on with the experiment on, most recent first, at most
|
|
/// `TypingConfigLimits.maxContexts`: what the review checks a config against.
|
|
var keyboards: [TypingConfigKeyboard] {
|
|
guard let data = defaults?.data(forKey: Keys.keyboards) else { return [] }
|
|
return (try? JSONDecoder().decode([TypingConfigKeyboard].self, from: data)) ?? []
|
|
}
|
|
|
|
/// Puts `keyboard` first; writes only when the list changes.
|
|
func record(_ keyboard: TypingConfigKeyboard) {
|
|
let now = keyboards
|
|
guard now.first != keyboard else { return }
|
|
let next = Array(([keyboard] + now.filter { $0.context != keyboard.context }).prefix(TypingConfigLimits.maxContexts))
|
|
if let data = try? JSONEncoder().encode(next) { defaults?.set(data, forKey: Keys.keyboards) }
|
|
}
|
|
}
|