Skip to content

Commit 2735a08

Browse files
committed
fix: document CPU-only constraint on determineLocalComposing
Every commit/delete/selection path calls determineLocalComposing inside runBlocking on the IME main thread. Safe today because all providers (Latin BreakIterator, Han shape engine) are CPU-only, but a future provider doing I/O would ANR on every keystroke. Pinned the invariant at both the interface contract (NlpProviders.kt) and the call site (AbstractEditorInstance.kt).
1 parent eeae492 commit 2735a08

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

app/src/main/kotlin/dev/patrickgold/florisboard/ime/editor/AbstractEditorInstance.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ abstract class AbstractEditorInstance(context: Context) {
351351
return editorInfo.isRichInputEditor && !editorInfo.inputAttributes.flagTextNoSuggestions
352352
}
353353

354+
// INVARIANT: must remain CPU-only (no I/O, no suspend delay). Called inside
355+
// runBlocking on the IME main thread from every commit/delete/selection path.
354356
private suspend fun determineLocalComposing(
355357
textBeforeSelection: CharSequence, localLastCommitPosition: Int
356358
): EditorRange {

app/src/main/kotlin/dev/patrickgold/florisboard/ime/nlp/NlpProviders.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ interface SuggestionProvider : NlpProvider {
203203
/**
204204
* When initializing composing text given a new context, the suggestion engine determines the composing range.
205205
* The default behavior gets the last word according to the current subtype's primaryLocale.
206+
*
207+
* **CONSTRAINT:** implementations MUST be CPU-only — no disk I/O, no network, no suspend
208+
* delay. This is called inside `runBlocking` on the IME main thread on every keystroke.
209+
*
206210
* @param subtype The current subtype used to determine word or character boundary.
207211
* @param textBeforeSelection The text whose end we want to compose.
208212
* @param breakIterators cache of BreakIterator(s) to determine boundary.

0 commit comments

Comments
 (0)