From fdffadf6fba593fa128cb4ba7c5b795d4e370cf9 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 18 Jun 2024 20:02:02 +0300 Subject: [PATCH] Add a workaround for a reported backspace issue in some apps --- .../futo/inputmethod/latin/RichInputConnection.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/java/src/org/futo/inputmethod/latin/RichInputConnection.java b/java/src/org/futo/inputmethod/latin/RichInputConnection.java index d28effc34..f7c1fcf2a 100644 --- a/java/src/org/futo/inputmethod/latin/RichInputConnection.java +++ b/java/src/org/futo/inputmethod/latin/RichInputConnection.java @@ -216,6 +216,13 @@ public final class RichInputConnection implements PrivateCommandPerformer { if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug(); } + public void restartBatchEdit() { + if(mNestLevel == 1) { + endBatchEdit(); + beginBatchEdit(); + } + } + /** * Reset the cached text and retrieve it again from the editor. * @@ -723,6 +730,12 @@ public final class RichInputConnection implements PrivateCommandPerformer { if (!isConnected()) { return null; } + + // In some editors, due to batch edit, we will receive stale information after having + // just performed an action (e.g. deleted text). Restarting batch edit will force + // the editor to process actions so far + restartBatchEdit(); + final CharSequence before = getTextBeforeCursorAndDetectLaggyConnection( OPERATION_GET_WORD_RANGE_AT_CURSOR, SLOW_INPUT_CONNECTION_ON_PARTIAL_RELOAD_MS,