diff --git a/app/src/main/java/com/osfans/trime/ime/core/Trime.java b/app/src/main/java/com/osfans/trime/ime/core/Trime.java index 8198923cd0..82e123b51c 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/Trime.java +++ b/app/src/main/java/com/osfans/trime/ime/core/Trime.java @@ -697,17 +697,20 @@ public void onUpdateSelection( super.onUpdateSelection( oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd); if ((candidatesEnd != -1) && ((newSelStart != candidatesEnd) || (newSelEnd != candidatesEnd))) { - // 移動光標時,更新候選區 - if ((newSelEnd < candidatesEnd) && (newSelEnd >= candidatesStart)) { - final int n = newSelEnd - candidatesStart; - Rime.setCaretPos(n); - updateComposing(); - } + // 移動光標時,commit + getCurrentInputConnection().finishComposingText(); + performEscape(); } if ((candidatesStart == -1 && candidatesEnd == -1) && (newSelStart == 0 && newSelEnd == 0)) { // 上屏後,清除候選區 performEscape(); } + if (candidatesEnd < newSelEnd || candidatesStart > newSelStart) { + // 點擊在"輸入文字"外,上屏 + getCurrentInputConnection().finishComposingText(); + performEscape(); + } + // Update the caps-lock status for the current cursor position. dispatchCapsStateToInputView(); } @@ -912,7 +915,13 @@ private boolean isComposing() { return Rime.isComposing(); } + /** + * Commit the current composing text together with the new text + * + * @param text the new text to be committed + */ public void commitText(String text) { + getCurrentInputConnection().finishComposingText(); activeEditorInstance.commitText(text, true); } diff --git a/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt b/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt index da52882538..3f6938f3c5 100644 --- a/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt +++ b/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt @@ -105,12 +105,10 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard if (tabTag.type === SymbolKeyboardType.SYMBOL) { service.inputSymbol(bean.text) } else if (tabTag.type !== SymbolKeyboardType.TABS) { - service.currentInputConnection?.run { - commitText(bean.text, 1) - if (tabTag.type !== SymbolKeyboardType.HISTORY) { - symbolHistory.insert(bean.text) - symbolHistory.save() - } + service.commitText(bean.text) + if (tabTag.type !== SymbolKeyboardType.HISTORY) { + symbolHistory.insert(bean.text) + symbolHistory.save() } } else { val tag = TabManager.get().getTabSwitchTabTag(position) @@ -162,7 +160,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard setListener( object : FlexibleAdapter.Listener { override fun onPaste(bean: DatabaseBean) { - service.currentInputConnection?.commitText(bean.text, 1) + service.commitText(bean.text) } override suspend fun onPin(bean: DatabaseBean) {