Skip to content

Commit

Permalink
fix: key sequence cannot switch keyboards and commit partial text
Browse files Browse the repository at this point in the history
  • Loading branch information
if-can authored and Bambooin committed Jan 19, 2025
1 parent c62cdd5 commit b771710
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ abstract class InputComponent(
@get:InputScope @get:Provides val rime: RimeSession,
) {
abstract val broadcaster: InputBroadcaster
abstract val commonKeyboardActionListener: CommonKeyboardActionListener
abstract val enterKeyLabel: EnterKeyLabelModule
abstract val quickBar: QuickBar
abstract val preedit: PreeditModule
abstract val windowManager: BoardWindowManager
abstract val preview: KeyPreviewChoreographer
abstract val keyboardWindow: KeyboardWindow
abstract val commonKeyboardActionListener: CommonKeyboardActionListener
abstract val liquidKeyboard: LiquidKeyboard
abstract val candidate: CandidateModule
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CommonKeyboardActionListener(
private val rime: RimeSession,
private val liquidKeyboard: LiquidKeyboard,
private val windowManager: BoardWindowManager,
private val lazyKeyboardWindow: Lazy<KeyboardWindow>,
) {
companion object {
/** Pattern for braced key event like `{Left}`, `{Right}`, etc. */
Expand All @@ -64,6 +65,8 @@ class CommonKeyboardActionListener(
private val PLACEHOLDER_PATTERN = Regex(".*(%([1-4]\\$)?s).*")
}

private val keyboardWindow by lazyKeyboardWindow

private val prefs = AppPrefs.defaultInstance()

private var shouldReleaseKey: Boolean = false
Expand Down Expand Up @@ -164,6 +167,9 @@ class CommonKeyboardActionListener(
}
}
}
KeyEvent.KEYCODE_EISU -> { // Switch keyboard
keyboardWindow.switchKeyboard(action.select)
}
KeyEvent.KEYCODE_LANGUAGE_SWITCH -> { // Switch IME
if (action.select == ".next") {
service.switchToNextIme()
Expand Down Expand Up @@ -328,8 +334,8 @@ class CommonKeyboardActionListener(
// FIXME: rime will not handle the key sequence when
// ascii_mode is on, there may be a better solution
// for this.
if (Rime.simulateKeySequence(slice)) {
if (Rime.isAsciiMode) {
if (Rime.isAsciiMode) {
if (Rime.simulateKeySequence(slice)) {
service.commitText(slice)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package com.osfans.trime.ime.keyboard
import android.content.Context
import android.content.res.Configuration
import android.text.InputType
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.FrameLayout
Expand Down Expand Up @@ -331,11 +330,8 @@ class KeyboardWindow(
return
}
}
if (action.code == KeyEvent.KEYCODE_EISU) { // Switch keyboard
switchKeyboard(action.select)
} else {
delegate.onAction(action)
}

delegate.onAction(action)
}
}
}

0 comments on commit b771710

Please sign in to comment.