Skip to content

Commit

Permalink
fix: commit any composing text when cursor's position changed
Browse files Browse the repository at this point in the history
When cursor's position is changed, commit the composing text.
If item in `LiquidKeyboard` is clicked, commit the composing
text first, then commit the item's text.

Fixes #1133
  • Loading branch information
goofyz authored and Bambooin committed Dec 7, 2023
1 parent f2d7792 commit dc27449
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
21 changes: 15 additions & 6 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit dc27449

@cabins
Copy link
Contributor

@cabins cabins commented on dc27449 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从这个commit开始,五笔等四码上屏的输入法受到了影响。具体的表现为,输入完四码,输入第五码的时候,第五码自动选择了第一个候选上屏了,这是不对的。希望能够double test一下。

Please sign in to comment.