mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Steps 3 and 4 of the phone side, on the shared reader's latest (21cdab23). - Settings › Keyboard › Typing configs (beside Vocabulary, only while the experiment is on): Hex defaults first, then every kept config newest first with its status (In use, Best so far, applied or opened when), Use on each row (one tap, deletes nothing), and Delete all. A config's page shows its facts (based on, made from another iPhone's typing), Use or Use Hex defaults instead, Rename, Share (the kept file, unchanged) and Delete, and its parts with their switches (TypingConfigParts, shared with the review sheet), applied at once while it is the one in use. - History: never refuses a new config. At 20 the oldest that is neither active nor best so far goes, and the review names it before Apply (replaces the old refusal). Not now keeps the parts switched off. Records this phone's export ids. - Experiment off: the sheet's first action is Turn on typing configs, which shows the review at once; Open Experiments stays as the quieter second. - The review now reads the keyboards the Hex keyboard recorded (TypingConfigSettings .keyboards) instead of a keyboard the app built (TypingConfigKeyboard.swift removed), and each item's own list, position, evidence and cleaned text instead of indexing by path; the note is the review's cleaned one. With no keyboard recorded yet the sheet says so under For another keyboard. hiddenCharacters has its sentence. The active config is compiled again when Hex comes to the foreground and a keyboard was recorded since. - Delete what Hex learned also deletes every typing config and goes back to Hex defaults; its confirmation says so. - Export for your agent (Typing logs, experiment on): the warning sheet every time (design §5's wording, a variant for fewer days), the days to include, then one zip: the bundled package (ios/TypingConfig/package as a folder resource), the chosen logs and state/ (phone.json as state.md defines it, the recorded keyboards' layout; vocabulary.json with each word's model cost and spell-checker answer). Deleted once the share sheet closes. - Hex's own dictation (handed to Hex, Action Button) applies the active config's dictation fixes after Learn how I type's, never to a translated dictation (TypingConfigDictation). - Strings in English and Simplified Chinese. Verified on the Studio (iOS 27.2): TypingLogTests 15 of 15 (history at the limit, apply and go back, dictation fixes off for translation); every screen on iPhone 17 Pro and iPhone SE (3rd gen) in English and 简体中文; the export of two real days (6.6 MB of logs) is a 772 KB zip, built in about 2.5 s from Continue; its state/ read by the package's overview.py; the share sheet offers Copy, Save to Files and More (AirDrop and other apps don't show on the simulator). Through the real keyboard (Full Access granted in the simulator's TCC database, the keyboard's typing log and Full Access report confirming it), a tap 3.35 pt inside r types R with Hex defaults and E with a key-off config applied through the review sheet (e's right edge +0.2, word-rule evidence), the keyboard closed and opened in between.
254 lines
11 KiB
Swift
254 lines
11 KiB
Swift
import SwiftUI
|
||
|
||
/// A typing config's parts as the review sheet and its page in Settings show them: what it
|
||
/// changes, grouped, each part with its own switch; key blocks for another keyboard; what Hex
|
||
/// skipped and why; and the file's note. A rendering of `TypingConfigReview`.
|
||
struct TypingConfigParts: View {
|
||
let review: TypingConfigReview
|
||
/// The parts switched off, by `Item.path`.
|
||
@Binding var partsOff: Set<String>
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
@State private var expanded: Set<TypingConfigGroup> = []
|
||
/// Rows a group shows before Show all.
|
||
static let shownRows = 6
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
if groups.isEmpty {
|
||
Self.plainCard(String(localized: "Nothing in this file applies to your keyboard. What Hex skipped is listed below."))
|
||
}
|
||
|
||
ForEach(groups, id: \.0) { group, items in
|
||
SettingsSectionHeader(title: LocalizedStringKey(group.title))
|
||
groupCard(group, items)
|
||
}
|
||
|
||
if !otherKeyboards.isEmpty {
|
||
SettingsSectionHeader(title: "For another keyboard")
|
||
SettingsCard {
|
||
// Nobody's keyboard is recorded until the Hex keyboard has been used with
|
||
// the experiment on and Full Access (TypingConfigSettings.keyboards).
|
||
if noKeyboardYet {
|
||
Self.textRow(
|
||
title: String(localized: "Hex hasn't seen your keyboard yet"),
|
||
lines: [String(localized: "Key positions are for one keyboard. Type with the Hex keyboard for a moment, then open Hex again: those made for it apply then.")]
|
||
)
|
||
SettingsDivider()
|
||
}
|
||
ForEach(Array(otherKeyboards.enumerated()), id: \.element.block) { n, check in
|
||
if n > 0 { SettingsDivider() }
|
||
Self.textRow(
|
||
title: String(localized: "Key positions for another keyboard"),
|
||
lines: TypingConfigContextWords.differences(check) + [otherKeyboardParts(check.block)]
|
||
)
|
||
}
|
||
}
|
||
}
|
||
|
||
if !skipped.isEmpty {
|
||
SettingsSectionHeader(title: "Skipped")
|
||
SettingsCard {
|
||
ForEach(Array(skipped.enumerated()), id: \.element.0) { n, entry in
|
||
if n > 0 { SettingsDivider() }
|
||
skippedRow(entry.0, entry.1)
|
||
}
|
||
}
|
||
}
|
||
|
||
if let note = review.note, !note.isEmpty {
|
||
SettingsSectionHeader(title: "From the file")
|
||
Self.plainCard(note, muted: false)
|
||
}
|
||
}
|
||
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: expanded)
|
||
}
|
||
|
||
/// Parts that apply and are switched on.
|
||
static func switchedOn(_ review: TypingConfigReview, partsOff: Set<String>) -> Int {
|
||
review.items.filter { $0.outcome.applies && $0.part != .note && !partsOff.contains($0.path) }.count
|
||
}
|
||
|
||
private var groups: [(TypingConfigGroup, [TypingConfigReview.Item])] {
|
||
let applying = review.items.filter { $0.outcome.applies }
|
||
return TypingConfigGroup.allCases.compactMap { group in
|
||
let items = applying.filter { TypingConfigGroup($0.part) == group }
|
||
return items.isEmpty ? nil : (group, items)
|
||
}
|
||
}
|
||
|
||
private var skipped: [(TypingConfigReview.Reason, [TypingConfigReview.Item])] {
|
||
var byReason: [TypingConfigReview.Reason: [TypingConfigReview.Item]] = [:]
|
||
for item in review.items {
|
||
// Another keyboard's parts are listed under For another keyboard.
|
||
if case .skipped(let reason) = item.outcome, reason != .forAnotherKeyboard { byReason[reason, default: []].append(item) }
|
||
}
|
||
return byReason.keys.sorted().map { ($0, byReason[$0] ?? []) }
|
||
}
|
||
|
||
private var noKeyboardYet: Bool { TypingConfigSettings().keyboards.isEmpty }
|
||
|
||
private var otherKeyboards: [TypingConfigReview.ContextCheck] {
|
||
review.contexts.filter { !$0.matches }
|
||
}
|
||
|
||
private func toggle(_ items: [TypingConfigReview.Item], on: Bool) {
|
||
for item in items {
|
||
if on { partsOff.remove(item.path) } else { partsOff.insert(item.path) }
|
||
}
|
||
}
|
||
|
||
private func groupCard(_ group: TypingConfigGroup, _ items: [TypingConfigReview.Item]) -> some View {
|
||
let showsAll = expanded.contains(group) || items.count <= Self.shownRows + 1
|
||
let shown = showsAll ? items : Array(items.prefix(Self.shownRows))
|
||
let allOn = items.allSatisfy { !partsOff.contains($0.path) }
|
||
return SettingsCard {
|
||
Text(group.detail)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.horizontal, 16)
|
||
.padding(.top, 12)
|
||
.padding(.bottom, 4)
|
||
// A long list gets one switch for all of it too.
|
||
if items.count > Self.shownRows {
|
||
SettingsToggleRow(
|
||
title: String(localized: "All \(items.count)"),
|
||
isOn: Binding(get: { allOn }, set: { toggle(items, on: $0) })
|
||
)
|
||
}
|
||
ForEach(Array(shown.enumerated()), id: \.element.path) { n, item in
|
||
if n > 0 || items.count > Self.shownRows { SettingsDivider() }
|
||
itemRow(item)
|
||
}
|
||
if !showsAll {
|
||
SettingsDivider()
|
||
Button {
|
||
expanded.insert(group)
|
||
} label: {
|
||
Text("Show all \(items.count)")
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.frame(maxWidth: .infinity, minHeight: 44, alignment: .leading)
|
||
.padding(.leading, 16)
|
||
.contentShape(Rectangle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
}
|
||
|
||
private func itemRow(_ item: TypingConfigReview.Item) -> some View {
|
||
let words = TypingConfigItemWords(item, review: review)
|
||
var lines: [String] = []
|
||
if let detail = words.detail { lines.append(detail) }
|
||
if let asked = TypingConfigItemWords.asked(item) { lines.append(asked) }
|
||
if let claim = TypingConfigItemWords.evidence(item, review: review) { lines.append(claim) }
|
||
return Toggle(isOn: Binding(
|
||
get: { !partsOff.contains(item.path) },
|
||
set: { toggle([item], on: $0) }
|
||
)) {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text(words.title)
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
ForEach(lines, id: \.self) { line in
|
||
Text(line)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
}
|
||
.tint(HexTheme.success)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 8)
|
||
.frame(minHeight: 50)
|
||
}
|
||
|
||
/// "Aim for O and O, bottom edge: kept in the file, not applied."
|
||
private func otherKeyboardParts(_ block: Int) -> String {
|
||
let labels = review.items.compactMap { item -> String? in
|
||
switch item.part {
|
||
case .aim(block, _), .zone(block, _): TypingConfigItemWords.label(item, review: review)
|
||
default: nil
|
||
}
|
||
}
|
||
return labels.isEmpty
|
||
? String(localized: "Kept in the file, not applied.")
|
||
: String(localized: "\(labels.formatted(.list(type: .and))): kept in the file, not applied.")
|
||
}
|
||
|
||
private func skippedRow(_ reason: TypingConfigReview.Reason, _ items: [TypingConfigReview.Item]) -> some View {
|
||
let labels = items.prefix(4).map { TypingConfigItemWords.label($0, review: review) }
|
||
let more = items.count - labels.count
|
||
let list = labels.joined(separator: ", ") + (more > 0 ? String(localized: " and \(more) more") : "")
|
||
return Self.textRow(title: reason.sentence, lines: [list])
|
||
}
|
||
|
||
static func textRow(title: String, lines: [String]) -> some View {
|
||
VStack(alignment: .leading, spacing: 3) {
|
||
Text(title)
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
ForEach(lines, id: \.self) { line in
|
||
Text(line)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 12)
|
||
}
|
||
|
||
static func plainCard(_ text: String, muted: Bool = true) -> some View {
|
||
Text(text)
|
||
.font(.system(size: 13))
|
||
.foregroundStyle(muted ? HexTheme.textMuted : HexTheme.textBase)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 12)
|
||
.background(HexTheme.bgBase, in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous))
|
||
}
|
||
}
|
||
|
||
/// Needs Full Access: why the keyboard can't use a config yet and where to turn it on.
|
||
struct TypingConfigFullAccessCard: View {
|
||
@Environment(\.openURL) private var openURL
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
VStack(alignment: .leading, spacing: 3) {
|
||
Text("Needs Full Access")
|
||
.font(.system(size: 14, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
Text("The keyboard can only use a typing config with Full Access. Turn on Allow Full Access in Settings › Apps › Hex › Keyboards, then apply.")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
Button {
|
||
if let url = URL(string: UIApplication.openSettingsURLString) { openURL(url) }
|
||
} label: {
|
||
HStack(spacing: 5) {
|
||
Text("Open Settings")
|
||
Image(systemName: "arrow.up.right")
|
||
.font(.system(size: 11, weight: .semibold))
|
||
}
|
||
.font(.system(size: 13, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.padding(.horizontal, 12)
|
||
.frame(height: 30)
|
||
.background(Color.white.opacity(0.09), in: Capsule())
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(14)
|
||
.background(HexTheme.bgBase, in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous))
|
||
}
|
||
}
|