Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
30 changes: 30 additions & 0 deletions app/src/test/java/helium314/keyboard/latin/AutoHideToolbarTest.kt
Original file line number Diff line number Diff line change
@@ -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))
}
}
Loading