From ce92ea68455c9a1b1e18b843321364403d27d12d Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Thu, 21 Mar 2024 22:38:33 -0500 Subject: [PATCH] Suppress InputLogic selection updates during transaction --- .../latin/inputlogic/InputLogic.java | 10 ++++++++ .../futo/inputmethod/latin/uix/UixManager.kt | 25 ++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java index e1730a828..0422baad3 100644 --- a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java @@ -111,6 +111,14 @@ public final class InputLogic { // Note: This does not have a composing span, so it must be handled separately. private String mWordBeingCorrectedByCursor = null; + private boolean isLogicSuppressedByExternalLogic = false; + public void startSuppressingLogic() { + isLogicSuppressedByExternalLogic = true; + } + public void endSuppressingLogic() { + isLogicSuppressedByExternalLogic = false; + } + /** * Create a new instance of the input logic. * @param latinIMELegacy the instance of the parent LatinIME. We should remove this when we can. @@ -354,6 +362,8 @@ public final class InputLogic { */ public boolean onUpdateSelection(final int oldSelStart, final int oldSelEnd, final int newSelStart, final int newSelEnd, final SettingsValues settingsValues) { + if(isLogicSuppressedByExternalLogic) return false; + if (mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart, oldSelEnd, newSelEnd)) { return false; } diff --git a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt index 8b837eff3..b3af07e0f 100644 --- a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt +++ b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.os.Build import android.os.VibrationEffect import android.os.Vibrator -import android.util.Log import android.view.View import android.view.WindowManager import android.view.inputmethod.InlineSuggestionsResponse @@ -65,30 +64,27 @@ import org.futo.inputmethod.updates.retrieveSavedLastUpdateCheckResult private class LatinIMEActionInputTransaction( private val inputLogic: InputLogic, - shouldApplySpace: Boolean + shouldApplySpace: Boolean, + private val context: Context ): ActionInputTransaction { private val isSpaceNecessary: Boolean private var isFinished = false + init { val priorText = inputLogic.mConnection.getTextBeforeCursor(1, 0) isSpaceNecessary = shouldApplySpace && !priorText.isNullOrEmpty() && !priorText.last().isWhitespace() - Log.i("LatinIMEActionInputTransaction", "Beginning batch edit due to input transaction") - inputLogic.mConnection.beginBatchEdit() - } - - private fun finish() { - isFinished = true - inputLogic.mConnection.endBatchEdit() - Log.i("LatinIMEActionInputTransaction", "Ending batch edit due to input transaction having been finished or cancelled") + inputLogic.startSuppressingLogic() } private fun transformText(text: String): String { return if(isSpaceNecessary) { " $text" } else { text } } + private var previousText = "" override fun updatePartial(text: String) { if(isFinished) return + previousText = text inputLogic.mConnection.setComposingText( transformText(text), 1 @@ -97,17 +93,16 @@ private class LatinIMEActionInputTransaction( override fun commit(text: String) { if(isFinished) return + isFinished = true inputLogic.mConnection.commitText( transformText(text), 1 ) - finish() + inputLogic.endSuppressingLogic() } override fun cancel() { - if(isFinished) return - inputLogic.mConnection.finishComposingText() - finish() + commit(previousText) } } @@ -125,7 +120,7 @@ class UixActionKeyboardManager(val uixManager: UixManager, val latinIME: LatinIM } override fun createInputTransaction(applySpaceIfNeeded: Boolean): ActionInputTransaction { - return LatinIMEActionInputTransaction(latinIME.inputLogic, applySpaceIfNeeded) + return LatinIMEActionInputTransaction(latinIME.inputLogic, applySpaceIfNeeded, latinIME) } override fun typeText(v: String) {