Skip to content
Closed
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
3 changes: 3 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<CjkCandidate>, selectedIndex: Int, preedit: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -147,11 +162,18 @@ 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
candidatesContainer.removeAllViews()
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
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,8 @@
<string name="cjk_lang_korean_title">韩语(韩文)</string>
<string name="cjk_lang_korean_summary">用于 2-Bulshik 和 Sebeolsik 布局的本机 Hangul 组合器</string>
<string name="cjk_engine_options_title">发动机实用程序</string>
<string name="cjk_tappable_preedit_title">原文可点击提交</string>
<string name="cjk_tappable_preedit_summary">点按候选栏左侧的 [拼音] 将其作为原始文本提交,效果与回车相同</string>
<string name="cjk_mock_engine_title">启用模拟引擎(调试)</string>
<string name="cjk_mock_engine_summary">未安装配套插件时使用内置模拟引擎</string>
<string name="cjk_clear_user_dict_title">清除 CJK 用户历史记录</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,8 @@ New dictionary:
<string name="cjk_lang_korean_title">Korean (Hangul)</string>
<string name="cjk_lang_korean_summary">Native Hangul combiner for 2-Bulshik and Sebeolsik layouts</string>
<string name="cjk_engine_options_title">Engine Utilities</string>
<string name="cjk_tappable_preedit_title">Tappable pre-edit text</string>
<string name="cjk_tappable_preedit_summary">Tap the bracketed pinyin on the left to commit it as raw text, same as pressing Enter</string>
<string name="cjk_mock_engine_title">Enable Mock Engine (Debug)</string>
<string name="cjk_mock_engine_summary">Use built-in mock engine when companion plugin is not installed</string>
<string name="cjk_clear_user_dict_title">Clear CJK User History</string>
Expand Down