From cd1ed0e1e7d92375a2361e0754fdd1d4e936fabb Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 5 Jan 2025 13:41:33 +0100 Subject: [PATCH] avoid doing unnecessary consistency checks during text reload / reset --- .../keyboard/latin/RichInputConnection.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java index 2afc52e0c..d40ae8718 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java +++ b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java @@ -470,18 +470,18 @@ public final class RichInputConnection implements PrivateCommandPerformer { final long startTime = SystemClock.uptimeMillis(); final CharSequence result = mIC.getTextBeforeCursor(n, flags); detectLaggyConnection(operation, timeout, startTime); - // inconsistent state can occur for (at least) two reasons - // 1. the app actively changes text field content, e.g. joplin when deleting "list markers like 2. - // 2. the app has outdated contents in the text field, e.g. notepad (com.farmerbb.notepad) returns the - // just deleted char right after deletion, instead of the correct one - // todo: understand where this inconsistent state comes from, is it really the other app's fault, or is it HeliBoard? - if (result != null) { - if (!checkTextBeforeCursorConsistency(result)) { - Log.w(TAG, "cached text out of sync, reloading"); - reloadCursorPosition(); - if (!DebugLogUtils.getStackTrace(2).contains("reloadTextCache")) // clunky bur effective protection against circular reference - reloadTextCache(); - } + + // only do the consistency check if we actually have text (i.e. we're not coming from some reload / reset) + if ((mCommittedTextBeforeComposingText.length() > 0 || mComposingText.length() > 0) + && result != null && !checkTextBeforeCursorConsistency(result)) { + // inconsistent state can occur for (at least) two reasons + // 1. the app actively changes text field content, e.g. joplin when deleting list markers like "2." + // 2. the app has outdated contents in the text field, e.g. com.farmerbb.notepad returns the + // just deleted char right after deletion, instead of the correct one + // todo: understand where this inconsistent state comes from, is it really the other app's fault, or is it HeliBoard? + Log.w(TAG, "cached text out of sync, reloading"); + reloadCursorPosition(); + reloadTextCache(); } return result; }