Skip to content
Merged
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
45 changes: 23 additions & 22 deletions app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class KeyboardWindow :
private var currentKeyboardId = ""
private var lastKeyboardId = ""
private var lastLockKeyboardId = ""
private var tempAsciiMode: Boolean? = null
private val cachedKeyboards = mutableMapOf<String, Pair<Keyboard, KeyboardView>>()
private val currentKeyboard: Keyboard? get() = cachedKeyboards[currentKeyboardId]?.first
private val currentKeyboardView: KeyboardView? get() = cachedKeyboards[currentKeyboardId]?.second
Expand Down Expand Up @@ -207,33 +208,23 @@ class KeyboardWindow :
}

override fun onStartInput(info: EditorInfo) {
var tempAsciiMode = false
val targetKeyboard =
when (info.imeOptions and EditorInfo.IME_FLAG_FORCE_ASCII) {
EditorInfo.IME_FLAG_FORCE_ASCII -> {
tempAsciiMode = true
".ascii"
}
EditorInfo.IME_FLAG_FORCE_ASCII -> ".ascii"
else -> {
when (info.inputType and InputType.TYPE_MASK_CLASS) {
InputType.TYPE_CLASS_NUMBER,
InputType.TYPE_CLASS_PHONE,
InputType.TYPE_CLASS_DATETIME,
-> {
tempAsciiMode = true
"number"
}
-> "number"
InputType.TYPE_CLASS_TEXT -> {
when (info.inputType and InputType.TYPE_MASK_VARIATION) {
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS,
InputType.TYPE_TEXT_VARIATION_PASSWORD,
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS,
InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD,
-> {
tempAsciiMode = true
".ascii"
}
-> ".ascii"
else -> ""
}
}
Expand All @@ -242,16 +233,26 @@ class KeyboardWindow :
}
}
switchKeyboard(targetKeyboard)
currentKeyboard?.let {
val isAsciiMode = rime.run { statusCached }.isAsciiMode
if (tempAsciiMode) {
if (!isAsciiMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", true) }
val isAsciiMode = rime.run { statusCached }.isAsciiMode
if (targetKeyboard == ".ascii" || targetKeyboard == "number") {
if (tempAsciiMode == null) {
tempAsciiMode = isAsciiMode
Comment on lines 235 to +239
}
if (!isAsciiMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", true) }
}
} else {
tempAsciiMode?.let { saved ->
if (isAsciiMode != saved) {
service.postRimeJob { setRuntimeOption("ascii_mode", saved) }
}
} else if (theme.generalStyle.resetAsciiModeOnFocusChange) {
val targetMode = if (it.resetAsciiMode) it.asciiMode else it.lastAsciiMode
if (isAsciiMode != targetMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", targetMode) }
tempAsciiMode = null
} ?: currentKeyboard?.let {
if (theme.generalStyle.resetAsciiModeOnFocusChange) {
val targetMode = if (it.resetAsciiMode) it.asciiMode else it.lastAsciiMode
if (isAsciiMode != targetMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", targetMode) }
}
}
}
}
Expand Down
Loading