From 4220bda6141c1717e6c84f915bf3eed1c98263c8 Mon Sep 17 00:00:00 2001 From: sspanak Date: Tue, 22 Apr 2025 17:26:13 +0300 Subject: [PATCH] fixed suggestion bar flashing without debouncing hacks --- .../github/sspanak/tt9/ime/TypingHandler.java | 13 ++++++++----- .../tt9/ime/helpers/SuggestionOps.java | 19 ++++++++++++++----- .../sspanak/tt9/ime/modes/InputMode.java | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java index 660bcc84..a354237c 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java @@ -131,7 +131,7 @@ public abstract class TypingHandler extends KeyPadHandler { if (repeat == 0 && mInputMode.onBackspace()) { getSuggestions(null); } else { - suggestionOps.commitCurrent(false); + suggestionOps.commitCurrent(false, true); mInputMode.reset(); deleteText(settings.getBackspaceAcceleration() && repeat > 0); } @@ -171,15 +171,18 @@ public abstract class TypingHandler extends KeyPadHandler { // Automatically accept the previous word, when the next one is a space or punctuation, // instead of requiring "OK" before that. // First pass, analyze the incoming key press and decide whether it could be the start of - // a new word. + // a new word. In case we do accept it, we preserve the suggestion list instead of clearing, + // to prevent flashing while the next suggestions are being loaded. else if (mInputMode.shouldAcceptPreviousSuggestion(key, hold)) { - String lastWord = suggestionOps.acceptIncomplete(); + // WARNING! Ensure the code after "acceptIncompleteAndKeepList()" does not depend on + // the suggestions in SuggestionOps, since we don't clear that list. + String lastWord = suggestionOps.acceptIncompleteAndKeepList(); mInputMode.onAcceptSuggestion(lastWord); autoCorrectSpace(lastWord, false, key); } // Auto-adjust the text case before each word, if the InputMode supports it. - if (suggestionOps.getCurrent().isEmpty()) { + if (mInputMode.getSuggestions().isEmpty()) { mInputMode.determineNextWordTextCase(); } @@ -188,7 +191,7 @@ public abstract class TypingHandler extends KeyPadHandler { return false; } - if (mInputMode.shouldSelectNextSuggestion() && !suggestionOps.isEmpty()) { + if (mInputMode.shouldSelectNextSuggestion() && !mInputMode.getSuggestions().isEmpty()) { scrollSuggestions(false); suggestionOps.scheduleDelayedAccept(mInputMode.getAutoAcceptTimeout()); } else { diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/SuggestionOps.java b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/SuggestionOps.java index f9e5a896..4854a85b 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/SuggestionOps.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/SuggestionOps.java @@ -97,7 +97,7 @@ public class SuggestionOps { public String acceptCurrent() { String word = getCurrent(); if (!word.isEmpty()) { - commitCurrent(true); + commitCurrent(true, true); } return word; @@ -106,24 +106,30 @@ public class SuggestionOps { public String acceptIncomplete() { String currentWord = this.getCurrent(); - commitCurrent(false); + commitCurrent(false, true); return currentWord; } + public String acceptIncompleteAndKeepList() { + commitCurrent(false, false); + return this.getCurrent(); + } + + public String acceptPrevious(Language language, int sequenceLength) { if (sequenceLength <= 0) { set(null); } String lastComposingText = getCurrent(language, sequenceLength - 1); - commitCurrent(false); + commitCurrent(false, true); return lastComposingText; } - public void commitCurrent(boolean entireSuggestion) { + public void commitCurrent(boolean entireSuggestion, boolean clearList) { if (!isEmpty()) { if (entireSuggestion) { textField.setComposingText(getCurrent()); @@ -131,7 +137,10 @@ public class SuggestionOps { textField.finishComposingText(); } - set(null); + + if (clearList) { + set(null); + } } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java index ecc8e5da..755949fe 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java @@ -96,6 +96,7 @@ abstract public class InputMode { onSuggestionsUpdated.run(); } + @NonNull public ArrayList getSuggestions() { ArrayList newSuggestions = new ArrayList<>(); for (String s : suggestions) {