From af0d70a13e4e28c68d3b00fdad5540765e6dc440 Mon Sep 17 00:00:00 2001 From: Songlin Jiang Date: Sun, 21 Jan 2024 00:33:15 +0200 Subject: [PATCH] Fix selected text get accidentally deleted in auto-compose When - starting to edit the input field - keyboard language / layout changes Signed-off-by: Songlin Jiang --- .../wolvic/ui/widgets/KeyboardWidget.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/KeyboardWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/KeyboardWidget.java index 7f896aef9ca..fb9239aad7c 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/KeyboardWidget.java @@ -371,7 +371,7 @@ private void initialize(Context aContext) { mAutoCompletionView.setExtendedHeight((int)(mWidgetPlacement.height * mWidgetPlacement.density)); mAutoCompletionView.setDelegate(this); - updateCandidates(); + updateCandidates(true); } @Override @@ -458,7 +458,7 @@ private void resetKeyboardLayout() { } handleShift(false); cleanComposingText(); - updateCandidates(); + updateCandidates(false); } private boolean isAttachToWindowWidget() { @@ -497,7 +497,7 @@ public void updateFocusedView(View aFocusedView) { } mCurrentKeyboard.clear(); - updateCandidates(); + updateCandidates(false); updateSpecialKeyLabels(); } @@ -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; } @@ -895,7 +895,7 @@ private void handleDomainChange(KeyboardSelectorView.Item aItem) { disableShift(getSymbolsKeyboard()); handleShift(false); hideOverlays(); - updateCandidates(); + updateCandidates(false); } public void updateDictionary() { @@ -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); @@ -999,7 +999,7 @@ private void handleDone() { mComposingText = ""; postInputCommand(() -> { displayComposingText(StringUtils.removeSpaces(mComposingDisplayText), ComposingAction.FINISH); - postUICommand(this::updateCandidates); + postUICommand(() -> updateCandidates(true)); }); return; } @@ -1116,7 +1116,7 @@ private void handleText(String aText, boolean skipCase) { handleShift(false); } - updateCandidates(); + updateCandidates(true); } private void handleVoiceInput() { @@ -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(); @@ -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); } @@ -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 { @@ -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; }