From 005683bb7ef8a1bee01650a0589242d2f50a2d85 Mon Sep 17 00:00:00 2001 From: Dimo Karaivanov Date: Fri, 28 Jul 2023 21:23:24 +0300 Subject: [PATCH] fixed auto-accepting causig MainView to hide unexpectedly when changing the input mode (#324) --- .../github/sspanak/tt9/ime/TraditionalT9.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/io/github/sspanak/tt9/ime/TraditionalT9.java b/src/io/github/sspanak/tt9/ime/TraditionalT9.java index f1c17d60..2c6c0de8 100644 --- a/src/io/github/sspanak/tt9/ime/TraditionalT9.java +++ b/src/io/github/sspanak/tt9/ime/TraditionalT9.java @@ -300,12 +300,7 @@ public class TraditionalT9 extends KeyPadHandler { return performOKAction(); } - String word = suggestionBar.getCurrentSuggestion(); - - mInputMode.onAcceptSuggestion(word); - commitCurrentSuggestion(); - autoCorrectSpace(word, true, KeyEvent.KEYCODE_ENTER); - resetKeyRepeat(); + acceptCurrentSuggestion(KeyEvent.KEYCODE_ENTER); return true; } @@ -504,11 +499,15 @@ public class TraditionalT9 extends KeyPadHandler { private boolean scheduleAutoAccept(int delay) { cancelAutoAccept(); + if (!suggestionBar.hasElements()) { + return false; + } + if (delay == 0) { - this.onOK(); + this.acceptCurrentSuggestion(); return true; } else if (delay > 0) { - autoAcceptHandler.postDelayed(this::autoAccept, delay); + autoAcceptHandler.postDelayed(this::acceptCurrentSuggestion, delay); } return false; @@ -520,10 +519,20 @@ public class TraditionalT9 extends KeyPadHandler { } - private void autoAccept() { - if (suggestionBar.hasElements()) { - this.onOK(); + private void acceptCurrentSuggestion(int fromKey) { + String word = suggestionBar.getCurrentSuggestion(); + if (word.isEmpty()) { + return; } + + mInputMode.onAcceptSuggestion(word); + commitCurrentSuggestion(); + autoCorrectSpace(word, true, fromKey); + resetKeyRepeat(); + } + + private void acceptCurrentSuggestion() { + acceptCurrentSuggestion(-1); } @@ -798,6 +807,7 @@ public class TraditionalT9 extends KeyPadHandler { if (mInputMode.isPassthrough() || isInputViewShown()) { return; } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { requestShowSelf(InputMethodManager.SHOW_IMPLICIT); } else {