Skip to content

Commit

Permalink
Fix selected text get accidentally deleted in auto-compose
Browse files Browse the repository at this point in the history
When
- starting to edit the input field
- keyboard language / layout changes

Signed-off-by: Songlin Jiang <[email protected]>
  • Loading branch information
HollowMan6 committed Jan 20, 2024
1 parent 2fc657e commit af0d70a
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private void initialize(Context aContext) {
mAutoCompletionView.setExtendedHeight((int)(mWidgetPlacement.height * mWidgetPlacement.density));
mAutoCompletionView.setDelegate(this);

updateCandidates();
updateCandidates(true);
}

@Override
Expand Down Expand Up @@ -458,7 +458,7 @@ private void resetKeyboardLayout() {
}
handleShift(false);
cleanComposingText();
updateCandidates();
updateCandidates(false);
}

private boolean isAttachToWindowWidget() {
Expand Down Expand Up @@ -497,7 +497,7 @@ public void updateFocusedView(View aFocusedView) {
}

mCurrentKeyboard.clear();
updateCandidates();
updateCandidates(false);
updateSpecialKeyLabels();
}

Expand Down Expand Up @@ -821,7 +821,7 @@ private void handleBackspace() {
mComposingText = mComposingText.substring(0, mComposingText.length() - 1);
mComposingText = mComposingText.trim();
}
postUICommand(KeyboardWidget.this::updateCandidates);
postUICommand(() -> KeyboardWidget.this.updateCandidates(true));
return;
}

Expand Down Expand Up @@ -895,7 +895,7 @@ private void handleDomainChange(KeyboardSelectorView.Item aItem) {
disableShift(getSymbolsKeyboard());
handleShift(false);
hideOverlays();
updateCandidates();
updateCandidates(false);
}

public void updateDictionary() {
Expand Down Expand Up @@ -963,7 +963,7 @@ private void handleLanguageChange(KeyboardInterface aKeyboard, Remember remember
mIsCapsLock = false;
handleShift(false);
hideOverlays();
updateCandidates();
updateCandidates(false);

String spaceText = mCurrentKeyboard.getSpaceKeyText(mComposingText).toUpperCase();
mCurrentKeyboard.getAlphabeticKeyboard().setSpaceKeyLabel(spaceText);
Expand Down Expand Up @@ -999,7 +999,7 @@ private void handleDone() {
mComposingText = "";
postInputCommand(() -> {
displayComposingText(StringUtils.removeSpaces(mComposingDisplayText), ComposingAction.FINISH);
postUICommand(this::updateCandidates);
postUICommand(() -> updateCandidates(true));
});
return;
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ private void handleText(String aText, boolean skipCase) {
handleShift(false);
}

updateCandidates();
updateCandidates(true);
}

private void handleVoiceInput() {
Expand Down Expand Up @@ -1182,7 +1182,7 @@ private void postDisplayCommand(Runnable aRunnable) {
}
}

private void updateCandidates() {
private void updateCandidates(boolean resetComposingText) {
if (mInputConnection == null || !mCurrentKeyboard.supportsAutoCompletion()) {
setAutoCompletionVisible(false);
updateSpecialKeyLabels();
Expand All @@ -1201,7 +1201,7 @@ private void updateCandidates() {
onAutoCompletionItemClick(candidates.words.get(0));
} else if (candidates != null) {
displayComposingText(candidates.composing, ComposingAction.DO_NOT_FINISH);
} else {
} else if (resetComposingText) {
mComposingText = "";
displayComposingText("", ComposingAction.FINISH);
}
Expand Down Expand Up @@ -1434,7 +1434,7 @@ public void onAutoCompletionItemClick(final KeyboardInterface.Words aItem) {

postInputCommand(() -> {
displayComposingText(aItem.value, ComposingAction.FINISH);
postUICommand(KeyboardWidget.this::updateCandidates);
postUICommand(() -> KeyboardWidget.this.updateCandidates(true));
});

} else {
Expand Down Expand Up @@ -1469,7 +1469,7 @@ public void afterTextChanged(Editable aEditable) {
// Text has been cleared externally (e.g. URLBar text clear button)
mComposingText = "";
mCurrentKeyboard.clear();
updateCandidates();
updateCandidates(true);
}
mInternalDeleteHint = false;
}
Expand Down

0 comments on commit af0d70a

Please sign in to comment.