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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,6 +125,7 @@ class InputLogic(
get() = mSuggestedWords

fun startInput(combiningSpec: String?, settingsValues: SettingsValues) {
mCapsLockFromRecapitalize = false
mEnteredText = null
mWordBeingCorrectedByCursor = null
mConnection.onStartInput()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading