diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 9eb4091a..47ed3834 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -1,6 +1,7 @@ package helium314.keyboard.keyboard import android.view.KeyEvent +import android.view.inputmethod.InputMethodSubtype import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode import helium314.keyboard.latin.LatinIME import helium314.keyboard.latin.RichInputMethodManager @@ -17,9 +18,12 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp private val keyboardSwitcher = KeyboardSwitcher.getInstance() private val settings = Settings.getInstance() - private var mSubtypeSwitchCount = 0 // for use with onLanguageSlide() private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers? + // language slide state + private var initialSubtype: InputMethodSubtype? = null + private var subtypeSwitchCount = 0 + // todo: maybe keep meta state presses to KeyboardActionListenerImpl, and avoid calls to press/release key private fun adjustMetaState(code: Int, remove: Boolean) { val metaCode = when (code) { @@ -86,7 +90,8 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp } override fun onEndSpaceSwipe(){ - mSubtypeSwitchCount = 0 + initialSubtype = null + subtypeSwitchCount = 0 } override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean { @@ -131,7 +136,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp private fun onLanguageSlide(steps: Int): Boolean { if (abs(steps) < settings.current.mLanguageSwipeDistance) return false val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(false) - if (subtypes.size - 1 <= abs(mSubtypeSwitchCount)) { // only allow if we are yet to cycle through all subtypes + if (subtypes.size <= 1) { // only allow if we have more than one subtype return false } // decide next or previous dependent on up or down @@ -140,8 +145,18 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp wantedIndex %= subtypes.size if (wantedIndex < 0) wantedIndex += subtypes.size - KeyboardSwitcher.getInstance().switchToSubtype(subtypes[wantedIndex]) - if (steps > 0) mSubtypeSwitchCount++ else mSubtypeSwitchCount-- + val newSubtype = subtypes[wantedIndex] + + // do not switch if we would switch to the initial subtype after cycling all other subtypes + if (initialSubtype == null) + initialSubtype = current + if (initialSubtype == newSubtype) { + if ((subtypeSwitchCount > 0 && steps > 0) || ((subtypeSwitchCount < 0 && steps < 0))) + return true + } + if (steps > 0) subtypeSwitchCount++ else subtypeSwitchCount-- + + KeyboardSwitcher.getInstance().switchToSubtype(newSubtype) return true }