From 7edbe12ddb9247e51c9ac6d22e7b35a20da8e4f3 Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Fri, 27 Nov 2026 15:37:18 +0530 Subject: [PATCH] fix(toolbar): fold the toolbar for the suggestions of a swipe (#870) With the toolbar open, "Auto hide toolbar" folded it for typed words but not after a swipe: a finished swipe sets its suggestions before its word is composing, so the composing check failed and the toolbar stayed over the suggestions. The suggestions of a finished swipe now count as suggestions for a word. Updates while still swiping and next-word predictions still keep the toolbar. --- .../java/helium314/keyboard/latin/LatinIME.kt | 13 +++++++- .../keyboard/latin/AutoHideToolbarTest.kt | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/helium314/keyboard/latin/AutoHideToolbarTest.kt diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt index 14dd273e7..ce5606fbf 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt @@ -38,6 +38,7 @@ import android.view.inputmethod.InputMethodSubtype import android.widget.FrameLayout import android.widget.Toast import androidx.annotation.RequiresApi +import androidx.annotation.VisibleForTesting import androidx.core.content.ContextCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsControllerCompat @@ -1841,7 +1842,8 @@ class LatinIME : InputMethodService(), noSuggestionsFromDictionaries ) { suggestionStripView?.setSuggestions(suggestedWords, richImm.currentSubtype.isRtlSubtype) - if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries && inputLogic.isComposingWord) { + if (shouldAutoHideToolbar(currentSettingsValues.mAutoHideToolbar, noSuggestionsFromDictionaries, + inputLogic.isComposingWord, suggestedWords.mInputStyle)) { suggestionStripView?.foldToolbar(!currentSettingsValues.mAutoShowToolbarNoSuggestions) } else if (currentSettingsValues.mAutoShowToolbarNoSuggestions && noSuggestionsFromDictionaries) { if (suggestionStripView?.isExternalSuggestionVisible != true) { @@ -2702,3 +2704,12 @@ private data class EditorKey( val fieldId: Int, val privateImeOptions: String? ) + +/** + * Whether "Auto hide toolbar" folds the toolbar for new suggestions: only for suggestions of a word, not + * for predictions. A finished swipe sets its suggestions before its word is composing, so its input + * style counts too (#870). + */ +@VisibleForTesting +internal fun shouldAutoHideToolbar(autoHideToolbar: Boolean, noSuggestions: Boolean, isComposingWord: Boolean, inputStyle: Int) = + autoHideToolbar && !noSuggestions && (isComposingWord || inputStyle == SuggestedWords.INPUT_STYLE_TAIL_BATCH) diff --git a/app/src/test/java/helium314/keyboard/latin/AutoHideToolbarTest.kt b/app/src/test/java/helium314/keyboard/latin/AutoHideToolbarTest.kt new file mode 100644 index 000000000..cadceab2d --- /dev/null +++ b/app/src/test/java/helium314/keyboard/latin/AutoHideToolbarTest.kt @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-3.0-only +package helium314.keyboard.latin + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class AutoHideToolbarTest { + @Test fun `typed word suggestions hide the toolbar`() { + assertTrue(shouldAutoHideToolbar(true, false, true, SuggestedWords.INPUT_STYLE_TYPING)) + } + + @Test fun `suggestions of a finished swipe hide the toolbar before the word is composing`() { + // #870: the swipe's suggestions are set before its word is inserted + assertTrue(shouldAutoHideToolbar(true, false, false, SuggestedWords.INPUT_STYLE_TAIL_BATCH)) + } + + @Test fun `suggestions while still swiping keep the toolbar`() { + assertFalse(shouldAutoHideToolbar(true, false, false, SuggestedWords.INPUT_STYLE_UPDATE_BATCH)) + } + + @Test fun `predictions keep the toolbar`() { + assertFalse(shouldAutoHideToolbar(true, false, false, SuggestedWords.INPUT_STYLE_PREDICTION)) + } + + @Test fun `nothing is hidden without the setting or without suggestions`() { + assertFalse(shouldAutoHideToolbar(false, false, true, SuggestedWords.INPUT_STYLE_TAIL_BATCH)) + assertFalse(shouldAutoHideToolbar(true, true, false, SuggestedWords.INPUT_STYLE_TAIL_BATCH)) + } +}