mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
What changed - The trackpad drags a point through the text at the text's own scale, in two dimensions, and puts the cursor at the nearest position (TrackpadCursor.State), as Apple's does. The text the field shares is laid out with the body font's own character widths, rows wrapped at the keyboard width less 40 pt, 20 pt lines. - Gain follows the finger's speed like Apple's: 1x slowly, 1.4x at 400 pt/s, 2x at 1,000, 2.6x at 2,000 (TrackpadCursor.gain), from a windowed speed of the touch's own timestamps, the same up, down or slanting. - Lines: one per line height (the first after half a line), x kept across short lines; it stops at a line's start and end and at the first/last line. Replaces the fixed 7.5 pt per character and 15.5 pt per line, and the move on past a line end into the next line. - Hosts share only the cursor's sentence/line (UITextView: "Lin" | "e two is a bit longer"), and drop a move that would leave the text (moves sent together add up). So at the edge of what's known the cursor waits for the host to show more, and past the first/last known line it steps just past it in one move, which the host makes only if text is there; no answer in 100 ms means it never moved. Before, moving down past the current line did nothing. - Offsets are UTF-16 (the proxy's unit): a 👍🏽 is one step, not four (three of them stalled inside the emoji). - Keys blank to keycaps 60% of the way to the backdrop (Apple: 242,242,247 on 226,227,232 light, 54 on 32 dark); Hex kept white keycaps. - No haptic on start or per character (Apple's keyboard asks for no feedback after the space bar's own); a second finger while the trackpad is on types nothing (it typed the blank key under it). Selection stays impossible: UITextDocumentProxy can't set one. - Trackpad code moved to FullKeyboardEngine+Trackpad.swift; FullKeyboardEngine.swift is 1,476 lines. Verified - Apple black box, iOS 27.2 simulator, same scripted HID gestures on Apple's, origin/dev and this build (UITextView logging selectedRange): 80 pt right at 150/400/1,000/2,000 pt/s gave 11/13/21/26 characters on Apple's, 10/10/10/10 before, 11/13/20/26 now; 140 pt down from line 1 reached line 5 on Apple's and now, nothing before; up 40 pt in 40 ms: 4 lines on both (before 3); 100 pt past a line end stops at it on both (before ran into the next line); column kept up 8 lines (index 7 on both). - Independent check (coordinator, iPhone 15 Pro / iOS 27.2 simulator, native UITextView, matched HID): build 56 up stays line 8 / down stays 5 / right moves 4; build 110 (19747178) up 8->6 / down stays 5 / right 4; this candidate up 8->6 / down 5->6 / right moves one, no text edits. - xcodebuild test: 624 tests, 0 failures, 1 skipped; after rebasing on dev3f374f42, FullKeyboardEngineTests' 118 pass.
61 lines
3 KiB
Swift
61 lines
3 KiB
Swift
import QuartzCore
|
|
import UIKit
|
|
|
|
/// The full keyboard's touches, as data: one finger's key, where it started and where it is,
|
|
/// and the state that makes a press an accent picker, a slide, a trackpad or a language
|
|
/// swipe. Kept beside the engine, like `SwipedWord`, so the engine's own file stays readable.
|
|
@MainActor
|
|
extension FullKeyboardEngine {
|
|
/// One finger on the keys.
|
|
struct ActiveTouch: Equatable {
|
|
var key: KeyboardKey
|
|
var startPoint: CGPoint
|
|
var point: CGPoint
|
|
/// A character that already went in because another key went down after it.
|
|
var committed: Bool
|
|
/// The page a 123/ABC press came from; releasing over a character returns there.
|
|
var returnLayer: KeyboardLayer?
|
|
/// A 123, #+= or shift press slid onto this character key: it shows the key's pop-up,
|
|
/// and letting go types it (`slideTarget`), as on Apple's keyboard.
|
|
var slideKey: KeyboardKey?
|
|
/// True once such a press slid onto a character key, so letting go back on the page
|
|
/// key is a slide taken back rather than a tap.
|
|
var hasSlid = false
|
|
/// True once a spacebar press crosses `trackpadActivationDistance`.
|
|
var isTrackpad = false
|
|
/// True once a spacebar press slides before its hold (`holdSpace`) while it switches
|
|
/// language: letting go far enough along switches instead of typing a space.
|
|
var isLanguageSwipe = false
|
|
/// The trackpad finger's last few moves, for its speed (`TrackpadCursor.speed(along:)`).
|
|
var trackpadPath: [TrackpadCursor.Sample] = []
|
|
/// The text the trackpad moves the cursor through (`TrackpadCursor.State`).
|
|
var trackpad: TrackpadCursor.State?
|
|
/// UTF-16 units the trackpad has moved the cursor, for Record typing logs.
|
|
var trackpadOffset = 0
|
|
/// True when the likelier next letter claimed this touch from the key under it; a
|
|
/// small move then keeps it rather than sliding back (`letterReach`).
|
|
var claimed = false
|
|
/// Where the finger went down, before a strip touch moved onto row 1 (Adaptive touch).
|
|
var downPoint: CGPoint = .zero
|
|
}
|
|
|
|
/// A press that types the character key it slides onto: 123, ABC and #+= (with a page to
|
|
/// go back to), and shift.
|
|
static func slidesToType(_ touch: ActiveTouch) -> Bool {
|
|
touch.returnLayer != nil || touch.key.kind == .shift
|
|
}
|
|
|
|
/// A language swipe's direction, or nil when it was too short or more up than along.
|
|
static func languageSwipeStep(from start: CGPoint, to end: CGPoint) -> Int? {
|
|
let dx = end.x - start.x
|
|
guard abs(dx) >= languageSwipeDistance, abs(dx) >= abs(end.y - start.y) else { return nil }
|
|
return dx < 0 ? 1 : -1
|
|
}
|
|
|
|
/// How far `point` is from `rect`: zero inside it.
|
|
static func distance(from point: CGPoint, to rect: CGRect) -> CGFloat {
|
|
let dx = max(rect.minX - point.x, 0, point.x - rect.maxX)
|
|
let dy = max(rect.minY - point.y, 0, point.y - rect.maxY)
|
|
return (dx * dx + dy * dy).squareRoot()
|
|
}
|
|
}
|