Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/verify-dictus-android/features/screens.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Captures are in [`../screens/`](../screens/), one `<screen-id>.png` each: Pixel
| `kbd.emoji` | Emoji picker (#192) under the keyboard bar (#139): category name, 8-column grid, bar at the bottom: ABC, 🔍, one emoji per category, ⌫ | tap 😊 | keyboard.emoji | categories / recents / search (field, result row, mini keyboard) / « Aucun résultat » | [stale](../screens/kbd.emoji.png) — still the androidx picker from before #192; re-take on the Pixel |
| `kbd.voice-note-reader` | — | — | voice-notes | absent | — |
| `kbd.smart-mode-fan` | — | — | smart-modes | absent | — |
| `kbd.suggestions` | The keyboard bar's centre slot (#139): 3 suggestion slots in place of ☰; the « Annuler » pill (8 s) after a dictation, above the suggestions; a notice above both | type in a scratch note | typing.autocorrect, dictation.keyboard | completions / the typed word alone while its completions are looked up (#374) / a kept typo and its offered readings, none bold (#388) / predictions / autocorrect undo chip `↶ mot` in slot 0 (#276) / dictation undo pill / « Aucun mot détecté » or « La dictée a échoué… » notice (3 s) / large font: a word too wide shrinks to its default-font size before « … » (#350) / « Coller » pill beside ☰ for a recent copy, with « Bouton Coller dans la barre » on (#420) | [yes](../screens/kbd.suggestions.png) |
| `kbd.suggestions` | The keyboard bar's centre slot (#139): 3 suggestion slots in place of ☰; the « Annuler » pill (8 s) after a dictation, above the suggestions; a notice above both | type in a scratch note | typing.autocorrect, dictation.keyboard | completions / the typed word alone while its completions are looked up (#374) / a kept typo and its offered readings, none bold (#388) / predictions / autocorrect undo chip `↶ mot` in slot 0 (#276) / dictation undo pill / « Aucun mot détecté » or « La dictée a échoué… » notice (3 s) / large font: a word too wide shrinks to its default-font size before « … » (#350) / « Coller » pill beside ☰ for a recent copy, with « Bouton Coller dans la barre » on (#420) / with `debug_suggestion_capsules` on (debug only, #434), the capsule look of `typing.suggestion-capsules` | [yes](../screens/kbd.suggestions.png) |
| `sys.settings.full-access` | — | — | dictation.keyboard | iOS-only | — |
| `share.voice-note` | « Transcrire avec Dictus » in Android's share sheet; a refusal is a dialog « Dictus ne peut pas transcrire ce fichier » over the sharing app | Partager on an audio file, with Pro (without Pro Dictus is not listed) | voice-notes | accepted (Dictus opens on « Messages vocaux ») / not audio / over 10 minutes / switched off | no — emulator captures in the #204 PR |
| `widget.live-activity` | — | — | live-activity | iOS-only | — |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ While typing with the Dictus keyboard, a three-slot bar above the keys offers co
- `typing.spatial-autocorrect`: Debug builds only, off by default (#385, iOS #1011). With the DataStore switch `debug_spatial_autocorrect` on, the space bar also reads where the finger landed on each letter key of the word (Hex's noisy-channel decoder, models `fr.hextm` and `en.hextm`): a letter tapped on the edge of its neighbour is read as the neighbour (`thinl` → `think`), a missed space splits (`inthe` → `in the`). Every rule that has the last word answers first, as iOS `correctionProposal`: an app or brand name kept or recased (`Discord`, `dictus` → `Dictus`), a spelling the words before choose (`il ma` → `m'a`, `a` → `à`), the accent rules (also when they keep the word, `reserve`) and the contractions (#386). It never reads a learned word, and it is weighed against the trie alone: it scores the trie's correction on the same taps and keeps the cheaper one. French and English only. A correction it made counts as `APPLIED` in the autocorrect tally, which does not tell it from the trie's (the coordinator's `lastSpaceDetail` says `SPATIAL`, the log does not). No row in Réglages. — présent (debug only)
- `typing.english-capital-i`: Debug builds only, off by default (#437, iOS #1112). With the DataStore switch `debug_english_rules` on, an English keyboard writes the pronoun with its capital mid-sentence on Space, a punctuation mark or Return: `i` → `I`, `im` → `I'm`, `ive` → `I've`, `i'm` `i'll` `i've` `i'd` typed with their apostrophe (straight or curly) → `I'm`… The bar's bold slot shows it. `ill`, `id`, `well` are left to `typing.english-contractions`; a field without a cap flag gets no capital the user did not type; a learned `i` stays (the undo chip teaches it). Never on a French, Spanish or German keyboard. No row in Réglages. — présent (debug only)
- `typing.english-contractions`: Debug builds only, same switch `debug_english_rules` (#437, iOS #1114). On an English keyboard, a word the engine keeps is chosen from the English typing model's word pairs (`spatial/en.hextm`, Hex's context choice): `id`/`I'd`, `ill`/`I'll`, `hell`/`he'll`, `shell`/`she'll`, `wed`/`we'd`, `lets`/`let's`, `well`/`we'll`, `its`/`it's`. On Space from the word before (`I think its` → `it's`, `Lets` → `Let's`), shown in the bar's bold slot; once the next word is kept, the word before is revised (`well see` → `we'll see`, `Its raining` → `It's raining`) in one replacement, if the text before the word is still what the last Space left. The undo chip shows and restores both words, and learns neither. `wont` → `won't` whatever the context. Kept: `very ill`, `wagged its tail`, `she lets me`, `pretty well`; a learned word, a word with its apostrophe or in capitals, across punctuation (`well, see`). A field without a cap flag writes `i'd`, `i'll`. No row in Réglages. — présent (debug only)
- `typing.suggestion-capsules`: Debug builds only, off by default (#434, iOS #502). With the DataStore switch `debug_suggestion_capsules` on, the bar is drawn as iOS 2.1's: words 17 sp regular in a muted ink (shrinking to 15 sp before « … »), 1 × 24 dp dividers, the bold slot (the word Space writes) in a neutral 36 dp capsule as wide as its slot instead of in bold (opaque white in light, white 37 % in dark), the undo chip a blue capsule of the same height (`↶ mot`, accent 12 %, same pulse); the dividers beside a capsule are hidden but keep their place. Display only: same words, slots, taps and 36 dp row. Off, the bar is develop's. No row in Réglages. — présent (debug only)
- `typing.apple-dictionary`: — absent (#437). iOS asks `UITextChecker` for an English word its list lacks (keeps `texted`, writes `venmo` → `Venmo`). Android's equivalent, the system spell checker (`android.view.textservice.SpellCheckerSession`), answers asynchronously, depends on the spell checker the user picked (often none on an emulator) and is not wired into the keyboard.
- `typing.contacts-and-replacements`: App and brand names are never corrected, as on iOS #1005: `Dictus` stays `Dictus` (never `Rictus`), and typed lowercase or with only a capital first letter Dictus, WhatsApp, Gmail, Instagram, Facebook, Snapchat, TikTok, LinkedIn, YouTube, Spotify, Netflix, ChatGPT, iPhone, iPad, iCloud, AirPods and MacBook take their casing on space (`iphone` → `iPhone`, with the casing in the bold slot). A mistyped name the dictionary corrects to one of them also takes its casing, on space and in the bar (`whatsap` → `WhatsApp`, #404; an Android difference, iOS writes `Whatsapp`); `discord` and `telegram` are only kept as typed. Personal dictionary shortcuts (iOS #873, #1022): « Raccourcis du dictionnaire personnel » in Réglages → Clavier, off by default (#424, iOS #873 and #1022). On, a shortcut of the phone's personal dictionary (Paramètres → Système → Langues → Dictionnaire personnel, `UserDictionary.Words`) expands at Space, a punctuation mark or Return, autocorrect on or off: `qqc` → « quelque chose », `Qqc` → « Quelque chose », a digit allowed (`adr1`). The undo chip puts the shortcut back and does not learn it; typed again, it expands again. Read at each keyboard opening; fields with no suggestions (password, email, URL) never expand. Contact names are not read (no `READ_CONTACTS`). — partiel (#397, #424: no contacts)
- `typing.auto-capitalization`: shift lights up on its own at the start of a field, after `.` `!` `?` and a space, and after a newline, then drops after one letter; tapping shift overrides it, caps lock is never touched; nothing in password, e-mail, URL, number fields or fields that do not ask for capitals. Same rules as iOS (`DictusKeyboardBridge.updateCapitalization`; the ID is not in the iOS map yet). — présent
Expand Down Expand Up @@ -56,6 +57,7 @@ Preconditions: Launch and Doctor OK, a scratch note focused, keyboard language F
- `typing.contacts-and-replacements`: add the shortcut on the emulator through Settings (`adb shell am start -a android.settings.USER_DICTIONARY_SETTINGS` → the language → Add → Word / Shortcut → Back twice; the AVD is in English), or with `adb shell "content insert --uri content://user_dictionary/words --bind word:s:'quelque chose' --bind shortcut:s:qqc --bind frequency:i:250"` (quote the whole remote command: the space splits it otherwise); remove it with `adb shell content delete --uri content://user_dictionary/words --where "shortcut='qqc'"`. Never on Pierre's Pixel without asking: his dictionary is his. Show the keyboard again after adding one: the list is read at each opening.
- `debug_ios_typing_fixes` (#443: the `typing.accents` held letter, the two thumbs and the apostrophe/Return border of `keyboard.layout`): turn it on with `python3 -I tools/keyboard-bench/dictus_prefs.py --serial <serial> set --bool debug_ios_typing_fixes true`, off with `false`; debuggable build only, no row in Réglages. Two overlapping fingers need `sendevent` multi-touch on the emulator, or Pierre's thumbs.
- `typing.spatial-autocorrect`: turn it on with `python3 -I tools/keyboard-bench/dictus_prefs.py --serial <serial> set --bool debug_spatial_autocorrect true` (it stops the app; show the keyboard again), off with `false`; debuggable build only. Tapping key centres by coordinate tells the decoder nothing the letters do not: its measure is `tools/keyboard-bench/run.sh --spatial on|off` (synthetic offsets), and for a real thumb the Pixel with Pierre.
- `typing.suggestion-capsules`: on with `python3 -I tools/keyboard-bench/dictus_prefs.py --serial <serial> set --bool debug_suggestion_capsules true` (it stops the app; show the keyboard again), off with `false`; debuggable build only. Type `bonjout`: `Bonjour` sits in the capsule; Space: `↶ Bonjout` in the blue capsule. Check light and dark (`set theme light|dark`).
- `typing.english-capital-i`, `typing.english-contractions`: turn them on with `python3 -I tools/keyboard-bench/dictus_prefs.py --serial <serial> set --bool debug_english_rules true` (it stops the app; show the keyboard again), off with `false`; debuggable build only. Type on the English keyboard in a field with a cap flag (the bench's `FieldActivity`): `so i think im late ` → `So I think I'm late `, `its raining. well see, i wont go ` → `It's raining. We'll see, I won't go `. Its measure is `tools/keyboard-bench/run.sh --english-rules on|off --langs en,fr`.
- `mcp__argent__keyboard` types through adb (`input text`), not through the Dictus keys: it never exercises suggestions or autocorrect.
- A word learned earlier (`typing.learned-words`) is no longer corrected, and the undo chip step **teaches the misspelling** (only « Réinitialiser les mots appris » removes it, and that forgets every learned word): on Pierre's Pixel, stop at the correction on space and skip the chip step; run the undo only on a test device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ object PreferenceKeys {
*/
val DEBUG_ENGLISH_RULES = booleanPreferencesKey("debug_english_rules")

/**
* The suggestion bar of iOS 2.1 (#434): the word Space writes in a neutral capsule rather than
* in bold, the undo chip a blue capsule. Display only. Read in debuggable builds only, shown in
* no settings screen, set with `tools/keyboard-bench/dictus_prefs.py`. Off when unset.
*/
val DEBUG_SUGGESTION_CAPSULES = booleanPreferencesKey("debug_suggestion_capsules")

// --- Dictus Pro (#3) ---
/**
* A purchase exists: the paid half of the Pro entitlement, iOS `SharedKeys.proActive`.
Expand Down
16 changes: 16 additions & 0 deletions ime/src/main/java/dev/pivisolutions/dictus/ime/DictusImeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import dev.pivisolutions.dictus.ime.ui.ApostropheReturnTaps
import dev.pivisolutions.dictus.ime.ui.KeyboardScreen
import dev.pivisolutions.dictus.ime.ui.LocalApostropheReturnTaps
import dev.pivisolutions.dictus.ime.ui.LocalIosTypingFixes
import dev.pivisolutions.dictus.ime.ui.LocalSuggestionCapsules
import dev.pivisolutions.dictus.ime.ui.LocalKeyboardSizing
import dev.pivisolutions.dictus.ime.ui.keyboardSizing
import dev.pivisolutions.dictus.ime.ui.usesFullscreenMode
Expand Down Expand Up @@ -349,6 +350,9 @@ class DictusImeService : LifecycleInputMethodService() {
private val _spatialEnabled = MutableStateFlow(false)
// iOS 2.1 typing fixes (#443): off unless their debug switch is on in a debuggable build.
private val _iosTypingFixesEnabled = MutableStateFlow(false)

// iOS 2.1 suggestion bar (#434): off unless its debug switch is on in a debuggable build.
private val _suggestionCapsulesEnabled = MutableStateFlow(false)
private val apostropheReturnTaps = ApostropheReturnTaps {
currentInputConnection?.getTextBeforeCursor(APOSTROPHE_RETURN_CONTEXT, 0) ?: ""
}
Expand Down Expand Up @@ -487,6 +491,16 @@ class DictusImeService : LifecycleInputMethodService() {
if (debuggable) Timber.d("English rules: %s", if (enabled) "on" else "off")
}
}
bindingScope.launch {
val debuggable = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
entryPoint.dataStore().data
.map { debuggable && it[PreferenceKeys.DEBUG_SUGGESTION_CAPSULES] == true }
.distinctUntilChanged()
.collect { enabled ->
_suggestionCapsulesEnabled.value = enabled
if (debuggable) Timber.d("Suggestion capsules: %s", if (enabled) "on" else "off")
}
}
bindingScope.launch {
entryPoint.dataStore().data
.map { it[PreferenceKeys.KEYBOARD_PASTE_OFFER_ENABLED] == true }
Expand Down Expand Up @@ -1260,12 +1274,14 @@ class DictusImeService : LifecycleInputMethodService() {
// Nothing covers the keyboard while the model loads, fails or is missing (#247).
val spatialEnabled by _spatialEnabled.collectAsState()
val iosTypingFixesEnabled by _iosTypingFixesEnabled.collectAsState()
val suggestionCapsulesEnabled by _suggestionCapsulesEnabled.collectAsState()
CompositionLocalProvider(
LocalKeyboardSizing provides sizing,
LocalDensity provides labelDensity,
LocalKeyTouches provides spatialAutocorrect.keyTouches.takeIf { spatialEnabled },
LocalIosTypingFixes provides iosTypingFixesEnabled,
LocalApostropheReturnTaps provides apostropheReturnTaps.takeIf { iosTypingFixesEnabled },
LocalSuggestionCapsules provides suggestionCapsulesEnabled,
) {
Column(modifier = Modifier.fillMaxWidth()) {
Box(modifier = Modifier.fillMaxWidth()) {
Expand Down
53 changes: 31 additions & 22 deletions ime/src/main/java/dev/pivisolutions/dictus/ime/ui/SuggestionBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ enum class SuggestionPresentationMode { COMPLETION, PREDICTION }
*
* [keepsTypedWord]: Space keeps the typed word, and the two other slots are corrections offered
* for a tap only, so none is bold (iOS `.candidates`, #388).
*
* With [LocalSuggestionCapsules] on (#434), the bar is drawn as iOS 2.1's ([CapsuleSuggestionBar]):
* the same slots and taps, the bold slot in a neutral capsule, the undo chip a blue capsule.
*/
@Composable
fun SuggestionBar(
Expand All @@ -74,6 +77,18 @@ fun SuggestionBar(
) {
val bold = boldSlot(mode, undoOffer, keepsTypedWord)
val slots = suggestionSlots(currentWord, suggestions, mode, undoOffer)
val onSlotTap: (Int, String) -> Unit = { index, text ->
if (undoOffer == null && mode == SuggestionPresentationMode.COMPLETION && index == 0) {
onCurrentWordSelected()
} else {
onSuggestionSelected(text, predictionToken.takeIf { mode == SuggestionPresentationMode.PREDICTION })
}
}

if (LocalSuggestionCapsules.current) {
CapsuleSuggestionBar(slots, pendingSlot = bold, undoOffer, onSlotTap, onUndoAutocorrect, modifier)
return
}

Row(
modifier = modifier
Expand All @@ -85,25 +100,13 @@ fun SuggestionBar(
if (undoOffer != null && index == 0) {
AutocorrectUndoChip(undoOffer, onUndoAutocorrect, Modifier.weight(1f))
} else {
val isRawInput = undoOffer == null && mode == SuggestionPresentationMode.COMPLETION && index == 0
Box(
modifier = Modifier
.weight(1f)
.height(36.dp)
.then(
if (text.isNotEmpty()) {
Modifier.clickable(role = Role.Button) {
if (isRawInput) {
onCurrentWordSelected()
} else {
onSuggestionSelected(
text,
predictionToken.takeIf {
mode == SuggestionPresentationMode.PREDICTION
},
)
}
}
Modifier.clickable(role = Role.Button) { onSlotTap(index, text) }
} else {
Modifier
},
Expand Down Expand Up @@ -185,14 +188,20 @@ private fun SuggestionText(text: String, fontWeight: FontWeight) {
/**
* The size factor of a suggestion in a slot [available] px wide, given its width at a factor
* ([widthAt]): 1 when it fits, otherwise the largest factor that fits, but never below its size
* at the default font (1 / [fontScale]); past that floor the text is ellipsized. At the default
* font it is always 1 (#350).
* at the default font (1 / [fontScale]) times [minScale]; past that floor the text is ellipsized.
* At the default font and a [minScale] of 1 it is always 1 (#350); the capsule bar shrinks a word
* to 15/17 first, as iOS does (#434).
*
* Text width does not scale exactly with the font size (glyph positions are rounded), so each
* candidate is measured rather than derived from the full-size width.
*/
internal fun suggestionTextScale(available: Int, fontScale: Float, widthAt: (Float) -> Int): Float {
val floor = minOf(1f, 1f / fontScale)
internal fun suggestionTextScale(
available: Int,
fontScale: Float,
minScale: Float = 1f,
widthAt: (Float) -> Int,
): Float {
val floor = minOf(1f, 1f / fontScale) * minScale
val fullWidth = widthAt(1f)
if (fullWidth <= available || floor >= 1f) return 1f
var scale = maxOf(floor, available.toFloat() / fullWidth)
Expand Down Expand Up @@ -283,8 +292,8 @@ private fun AutocorrectUndoChip(
}

// iOS SuggestionBarView.undoChip and triggerUndoPulse.
private const val UNDO_REST_ALPHA = 0.12f
private const val UNDO_PULSE_ALPHA = 0.35f
private const val UNDO_PULSE_SCALE = 1.05f
private const val UNDO_PULSE_HOLD_MS = 80L
private const val UNDO_PULSE_EASE_MS = 450
internal const val UNDO_REST_ALPHA = 0.12f
internal const val UNDO_PULSE_ALPHA = 0.35f
internal const val UNDO_PULSE_SCALE = 1.05f
internal const val UNDO_PULSE_HOLD_MS = 80L
internal const val UNDO_PULSE_EASE_MS = 450
Loading
Loading