diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt index 61aaed33e..2042336d9 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt @@ -564,6 +564,9 @@ class LatinIME : InputMethodService(), cjkCandidateStripView?.onCandidateClickListener = { index -> CjkInputManager.getInstance(this).selectCandidate(index, currentInputConnection) } + cjkCandidateStripView?.onPreeditClickListener = { + CjkInputManager.getInstance(this).commitRawInput(currentInputConnection) + } CjkInputManager.getInstance(this).setUiListener(object : CjkInputManager.CjkUiListener { override fun onUpdateCandidates(candidates: List, selectedIndex: Int, preedit: String) { diff --git a/app/src/main/java/helium314/keyboard/latin/cjk/CjkCandidateStripView.kt b/app/src/main/java/helium314/keyboard/latin/cjk/CjkCandidateStripView.kt index 7a332005e..412c50dd1 100644 --- a/app/src/main/java/helium314/keyboard/latin/cjk/CjkCandidateStripView.kt +++ b/app/src/main/java/helium314/keyboard/latin/cjk/CjkCandidateStripView.kt @@ -13,6 +13,7 @@ import android.widget.TextView import helium314.keyboard.latin.R import helium314.keyboard.latin.common.ColorType import helium314.keyboard.latin.settings.Settings +import helium314.keyboard.latin.utils.prefs /** * Horizontally scrollable candidate bar for CJK input. @@ -33,6 +34,8 @@ class CjkCandidateStripView @JvmOverloads constructor( private val nextButton: ImageButton var onCandidateClickListener: ((index: Int) -> Unit)? = null + var onPreeditClickListener: (() -> Unit)? = null + private var preeditText: String = "" init { orientation = HORIZONTAL @@ -45,6 +48,15 @@ class CjkCandidateStripView @JvmOverloads constructor( prevButton = findViewById(R.id.cjk_strip_prev_page) nextButton = findViewById(R.id.cjk_strip_next_page) + val ripple = android.util.TypedValue() + if (context.theme.resolveAttribute(android.R.attr.selectableItemBackground, ripple, true)) { + preeditView.setBackgroundResource(ripple.resourceId) + } + preeditView.isClickable = true + preeditView.setOnClickListener { + if (preeditText.isNotEmpty()) onPreeditClickListener?.invoke() + } + prevButton.setOnClickListener { scrollView.smoothScrollBy(-scrollView.width / 2, 0) } @@ -88,6 +100,9 @@ class CjkCandidateStripView @JvmOverloads constructor( colors?.setBackground(this, ColorType.STRIP_BACKGROUND) // 1. Update Pre-edit string + preeditText = preedit + preeditView.isClickable = context.prefs() + .getBoolean(PREF_TAPPABLE_PREEDIT, DEFAULT_TAPPABLE_PREEDIT) if (preedit.isNotEmpty()) { preeditView.text = "[$preedit]" preeditView.setTextColor(accentColor) @@ -147,6 +162,7 @@ class CjkCandidateStripView @JvmOverloads constructor( * Clears candidate list and pre-edit text from the strip. */ fun clear() { + preeditText = "" preeditView.text = "" preeditView.visibility = View.GONE dividerView.visibility = View.GONE @@ -154,4 +170,10 @@ class CjkCandidateStripView @JvmOverloads constructor( prevButton.visibility = View.GONE nextButton.visibility = View.GONE } + + companion object { + /** Whether tapping the pre-edit text commits it as raw input. */ + const val PREF_TAPPABLE_PREEDIT = "pref_cjk_tappable_preedit" + const val DEFAULT_TAPPABLE_PREEDIT = true + } } diff --git a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt index 3a8117a34..45984efa2 100644 --- a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt @@ -148,6 +148,18 @@ class CjkInputManager private constructor(private val context: Context) { return false } + /** + * Commits the current raw pre-edit text by replaying the Enter key, which the engines treat + * as "commit pre-edit as-is". + */ + fun commitRawInput(ic: InputConnection?): Boolean { + if (!isComposing) return false + val engine = CjkPluginLoader.getEngine(context) ?: return false + if (!engine.processKey(KeycodeTranslator.XK_RETURN)) return false + syncStateWithInputConnection(engine, ic) + return true + } + /** * Clears active composition in both the engine and the InputConnection. */ diff --git a/app/src/main/java/helium314/keyboard/settings/screens/CjkSettingsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/CjkSettingsScreen.kt index 282f09572..a23db9fdb 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/CjkSettingsScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/CjkSettingsScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.R +import helium314.keyboard.latin.cjk.CjkCandidateStripView import helium314.keyboard.latin.cjk.CjkPluginLoader import helium314.keyboard.settings.SearchSettingsScreen import helium314.keyboard.settings.preferences.LoadCjkPluginPreference @@ -132,6 +133,13 @@ fun CjkSettingsScreen( ) } + SwitchPreference( + name = stringResource(R.string.cjk_tappable_preedit_title), + description = stringResource(R.string.cjk_tappable_preedit_summary), + key = CjkCandidateStripView.PREF_TAPPABLE_PREEDIT, + default = CjkCandidateStripView.DEFAULT_TAPPABLE_PREEDIT + ) + Preference( name = stringResource(R.string.cjk_clear_user_dict_title), description = stringResource(R.string.cjk_clear_user_dict_summary), diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a05133909..79233990a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1534,6 +1534,8 @@ 韩语(韩文) 用于 2-Bulshik 和 Sebeolsik 布局的本机 Hangul 组合器 发动机实用程序 + 原文可点击提交 + 点按候选栏左侧的 [拼音] 将其作为原始文本提交,效果与回车相同 启用模拟引擎(调试) 未安装配套插件时使用内置模拟引擎 清除 CJK 用户历史记录 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afa0dfb00..b440e90c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2067,6 +2067,8 @@ New dictionary: Korean (Hangul) Native Hangul combiner for 2-Bulshik and Sebeolsik layouts Engine Utilities + Tappable pre-edit text + Tap the bracketed pinyin on the left to commit it as raw text, same as pressing Enter Enable Mock Engine (Debug) Use built-in mock engine when companion plugin is not installed Clear CJK User History