From: AIKeyboard AI Integration Date: Wed, 09 Apr 2025 00:00:00 +0000 Subject: [PATCH 1/3] Add AI spell correction trigger hook in InputLogic After a sentence-ending punctuation character (. ! ? ...) is committed to the InputConnection, notify AiTriggerHook with the text before the cursor so the AI correction engine can run in the background. Field name confirmed: mLatinIME (type LatinIME, first constructor parameter). The hook is debounced (500ms) and async — the IME main thread is never blocked. --- .../keyboard/latin/inputlogic/InputLogic.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -1228,6 +1228,19 @@ final class InputLogic { mConnection.commitCodePoint(codePoint); + // === AI SPELL CORRECTION HOOK === + // Runs async on Dispatchers.IO via coroutine — does not block the IME thread. + // mLatinIME is confirmed non-null here (it's set in the constructor). + if (helium314.keyboard.latin.ai.AiTriggerHook.isSentenceEnder(codePoint) + && mLatinIME.getAiTriggerHook() != null) { + final CharSequence beforeCursor = + mConnection.getTextBeforeCursor(500, 0); + if (beforeCursor != null) { + mLatinIME.getAiTriggerHook() + .onSentenceEndDetected(beforeCursor.toString()); + } + } + // === END AI SPELL CORRECTION HOOK === + if (isInlineEmojiSearchAction()) { inputTransaction.setRequiresUpdateSuggestions(); } else {