mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
X tester Brandon McConnell: "no smart quotes/etc." Hex typed straight quotes and two
hyphens everywhere. Apple's keyboard (black box, iOS 27.2 simulator, a UITextView with
each trait on and off, a text field, Messages, and 15 of its keyboards):
- ' and " open at the start, after a space or new line, a bracket or an opening quote,
and close elsewhere: 'hi' it's "yes" ("ok") 5'9" became ‘Hi’ it’s “yes” (“ok”) 5’9”.
- A second hyphen makes an em dash (a--b is a—b, a third stays a hyphen, delete takes
the dash whole); " - " stays.
- Autocorrect's apostrophes are ’ (Don’t, I’ll), and the strip shows I’m.
- smartQuotesType or smartDashesType .no turns each off; Messages' composer types
straight quotes and -- (both off there).
- Quotes per keyboard: „ “ ‚ ‘ in German and Swiss German (the apostrophe key types ‘
even inside a word), « » with no-break spaces inside in French, Canadian and Swiss
French, „ ” ‚ ’ in Polish, « » in Norwegian, Russian and Ukrainian, “ ” ‘ ’ in English,
Spanish, Italian, Portuguese and Romanian. Serbian (no simulator keyboard) gets the
English ones.
- smartInsertDeleteType changed nothing it types: after a picked suggestion, , . ! ? ;
: ) took the suggestion's space ("Hello,") with it on or off; " ( @ kept it, and so did
a space typed by hand ("Hello .").
Hex now does the same:
- SmartPunctuation.swift: SmartQuotes per KeyboardLanguage, curled() for typed keys and
for autocorrect, suggestion, swipe and revert text, the em dash in typeIntoField, and
the strip's apostrophes (displayed). Accent picks, emoji and text replacements go in as
they are. KeyboardTextTarget gains smartQuotesType and smartDashesType (the proxy's;
nil, off, for fixtures); .default counts as on, Smart Punctuation's default, which a
keyboard can't read.
- The keys still reason with straight quotes: FullKeyboardEngine reads textBefore, the
field's text with curly quotes made straight one for one (SmartPunctuation.plain), so
tokens, revisions, reverts and swipes keep matching what they typed.
- dropsSuggestionSpace: , . ! ? ; : ) right after a picked suggestion delete its space.
- AutocorrectEngine.midSentenceMarks gains ' (what ’ reads as now).
Verified on the Studio (iPhone 17, iOS 27.2 simulator): AutocorrectEngineTests,
FullKeyboardEngineTests, TypingLogTests and EmojiSuggesterTests pass, with new
testSmartQuotesAndDashesFollowTheFieldAsOnApplesKeyboard, testSmartQuotesFollowTheKeysLanguage
and testMarksGoAgainstAPickedSuggestion. Live in the simulator's HEXKeyboard (Release, App
Group) in a UITextView host: 'hi' it's "yes" well--known dont typed ‘hi’ it’s “yes”
well—known don’t, straight quotes with smartQuotesType .no, well--known with smartDashesType
.no, and the strip showed I’m.
59 lines
3.1 KiB
Swift
59 lines
3.1 KiB
Swift
import UIKit
|
|
|
|
/// Delete after an autocorrection, as on Apple's keyboard (black box, iOS 27.2): delete takes
|
|
/// only the space or mark after the corrected words, and Apple's text view then shows what you
|
|
/// typed in a bubble with an undo arrow. A keyboard can't draw in the text, so the strip's left
|
|
/// slot offers it instead, highlighted with the same arrow (`KeyboardSuggestion.Kind.revert`);
|
|
/// tapping it puts back what you typed, without the space, and space after that keeps it. The
|
|
/// offer comes back whenever the cursor is at the end of the latest autocorrection again
|
|
/// (deleting back to it), as Apple's bubble does, and goes once a newer one replaces it.
|
|
@MainActor
|
|
extension FullKeyboardEngine {
|
|
/// `suggestions` with the revert in the left slot, in place of the word as it reads (which
|
|
/// space keeps anyway), while the cursor is right after the latest autocorrection.
|
|
func offeringRevert(_ suggestions: [KeyboardSuggestion]) -> [KeyboardSuggestion] {
|
|
guard let correction = autocorrect.revertibleCorrection(before: textBefore) else {
|
|
return suggestions
|
|
}
|
|
let revert = KeyboardSuggestion(displayText: correction.original, replacement: correction.original, kind: .revert)
|
|
let others = suggestions.filter {
|
|
$0.kind != .keepLiteral && $0.replacement.caseInsensitiveCompare(correction.original) != .orderedSame
|
|
}
|
|
return [revert] + others.prefix(2)
|
|
}
|
|
}
|
|
|
|
extension AutocorrectEngine {
|
|
/// The latest autocorrection, which the strip offers to revert while the cursor is right
|
|
/// after it, as Apple's keyboard offers its bubble (black box, iOS 27.2): delete takes only
|
|
/// the space or mark after it, and the cursor may come back to it later.
|
|
struct AppliedCorrection: Equatable {
|
|
/// One word the revert puts back as typed (`from`), and what autocorrect made it.
|
|
struct Change: Equatable {
|
|
let from: String
|
|
let to: String
|
|
/// The language the fix was made in, for what the keys learn from reverting it.
|
|
var language: KeyboardLanguage? = nil
|
|
}
|
|
|
|
/// What you typed ("teh", "well see", "ofthe").
|
|
let original: String
|
|
/// What autocorrect put in its place, without the space or mark after it.
|
|
let corrected: String
|
|
/// The words in `original` that autocorrect changed; the revert keeps each as typed.
|
|
let changes: [Change]
|
|
/// The text before the cursor right after `corrected`.
|
|
let anchor: String
|
|
|
|
/// How much of the text before the cursor must read as `anchor`: hosts give a window of
|
|
/// it, which may start elsewhere once the text is long.
|
|
static let anchorTail = 64
|
|
|
|
/// Whether the cursor is right after `corrected`, with the same text before it.
|
|
func isAtEnd(of before: String?) -> Bool {
|
|
guard let before, before.hasSuffix(corrected) else { return false }
|
|
guard anchor.count >= Self.anchorTail, before.count >= Self.anchorTail else { return before == anchor }
|
|
return before.suffix(Self.anchorTail) == anchor.suffix(Self.anchorTail)
|
|
}
|
|
}
|
|
}
|