diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.kt b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.kt index 2c3efc08c..3a0cf6615 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.kt +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.kt @@ -87,6 +87,8 @@ class InputLogic( // the composing word at the time the shift key was pressed down, null if there was none // used to tell a tap on shift from typing a letter while holding shift private var mTypedWordOnShiftPress: String? = null + /** caps lock was enabled by [recapitalizeComposingWord], it is released when the word is finished */ + private var mCapsLockFromRecapitalize = false private var mDeleteCount = 0 private var mLastKeyTime = 0L @@ -123,6 +125,7 @@ class InputLogic( get() = mSuggestedWords fun startInput(combiningSpec: String?, settingsValues: SettingsValues) { + mCapsLockFromRecapitalize = false mEnteredText = null mWordBeingCorrectedByCursor = null mConnection.onStartInput() @@ -433,6 +436,12 @@ class InputLogic( if (KeyCode.DELETE != processedEvent.keyCode) { mEnteredText = null } + // caps lock only for the word that was changed to upper case with shift, the next word is normal again + if (mCapsLockFromRecapitalize && !mWordComposer.isComposingWord()) { + mCapsLockFromRecapitalize = false + KeyboardSwitcher.getInstance().setCapsLock(false) + inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW) + } mConnection.endBatchEdit() return inputTransaction } @@ -1832,7 +1841,8 @@ class InputLogic( setComposingTextInternal(replacement, 1) mConnection.endBatchEdit() // typing should continue in the same case: caps lock for an upper case word, lower case otherwise - KeyboardSwitcher.getInstance().setCapsLock(mRecapitalizeStatus.getCurrentMode() == RecapitalizeMode.ALL_UPPER) + mCapsLockFromRecapitalize = mRecapitalizeStatus.getCurrentMode() == RecapitalizeMode.ALL_UPPER + KeyboardSwitcher.getInstance().setCapsLock(mCapsLockFromRecapitalize) return true } diff --git a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt index 23f26c2fe..54ddc4118 100644 --- a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt @@ -386,6 +386,21 @@ class InputLogicTest { assertEquals("hello ", text) } + @Test fun `caps lock from shift on a word ends with the word`() { + reset() + latinIME.prefs().edit { putBoolean(Settings.PREF_SHIFT_RECAPITALIZES_WORD, true) } + val capsLockFromRecapitalize = InputLogic::class.java.getDeclaredField("mCapsLockFromRecapitalize").apply { isAccessible = true } + chainInput("hello") + shiftTap() + shiftTap() + assertEquals("HELLO", composingText) + assertEquals(true, capsLockFromRecapitalize.getBoolean(inputLogic)) + input('X') // still the same word: caps lock stays + assertEquals(true, capsLockFromRecapitalize.getBoolean(inputLogic)) + input(' ') // word finished: caps lock is released + assertEquals(false, capsLockFromRecapitalize.getBoolean(inputLogic)) + } + @Test fun `shift at end of word does not change the word by default`() { reset() chainInput("hello")