From 474839f60b67d5674301da2bb8fedf34837a717f Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Mon, 29 Apr 2024 22:16:45 -0400 Subject: [PATCH] Add option to undo slide deletion --- .../inputmethod/keyboard/PointerTracker.java | 4 +--- .../inputmethod/latin/LatinIMELegacy.java | 21 +++++++++++++++++++ .../inputmethod/latin/SuggestedWords.java | 1 + .../latin/inputlogic/InputLogic.java | 12 +++++++++++ .../latin/xlm/LanguageModelFacilitator.kt | 14 +++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/java/src/org/futo/inputmethod/keyboard/PointerTracker.java b/java/src/org/futo/inputmethod/keyboard/PointerTracker.java index 4e59e44ba..6e602b0fa 100644 --- a/java/src/org/futo/inputmethod/keyboard/PointerTracker.java +++ b/java/src/org/futo/inputmethod/keyboard/PointerTracker.java @@ -1002,9 +1002,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element, if(mCursorMoved && currentKey.getCode() == Constants.CODE_DELETE) { sListener.onUpWithDeletePointerActive(); - } - - if(mCursorMoved) { + } else if(mCursorMoved) { sListener.onUpWithPointerActive(); } diff --git a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java index 40dc96c1c..01384e574 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java +++ b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java @@ -1422,6 +1422,27 @@ public class LatinIMELegacy implements KeyboardActionListener, @Override public void onUpWithDeletePointerActive() { if (mInputLogic.mConnection.hasSelection()) { + CharSequence selection = mInputLogic.mConnection.getSelectedText(0); + if(selection != null) { + ArrayList info = new ArrayList<>(); + info.add(new SuggestedWordInfo( + selection.toString(), + "", + 0, + SuggestedWordInfo.KIND_UNDO, + null, + 0, + 0)); + showSuggestionStrip(new SuggestedWords(info, + null, + null, + false, + false, + false, + 0, + 0)); + ((LatinIME)mInputMethodService).languageModelFacilitator.ignoreNextUpdate(); + } onCodeInput( Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, diff --git a/java/src/org/futo/inputmethod/latin/SuggestedWords.java b/java/src/org/futo/inputmethod/latin/SuggestedWords.java index 6138d0ab8..8da46953b 100644 --- a/java/src/org/futo/inputmethod/latin/SuggestedWords.java +++ b/java/src/org/futo/inputmethod/latin/SuggestedWords.java @@ -256,6 +256,7 @@ public class SuggestedWords { public static final int KIND_RESUMED = 9; public static final int KIND_OOV_CORRECTION = 10; // Most probable string correction public static final int KIND_EMOJI_SUGGESTION = 11; + public static final int KIND_UNDO = 12; public static final int KIND_FLAG_POSSIBLY_OFFENSIVE = 0x80000000; public static final int KIND_FLAG_EXACT_MATCH = 0x40000000; diff --git a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java index 0ae1d83e3..5dc9a48e1 100644 --- a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java @@ -303,6 +303,18 @@ public final class InputLogic { // Manual pick affects the contents of the editor, so we take note of this. It's important // for the sequence of language switching. inputTransaction.setDidAffectContents(); + + if(suggestionInfo.mKindAndFlags == SuggestedWordInfo.KIND_UNDO) { + inputTransaction.setRequiresUpdateSuggestions(); + + mConnection.finishComposingText(); + mWordComposer.reset(); + + mConnection.commitText(suggestionInfo.mWord, 1); + + return inputTransaction; + } + mConnection.beginBatchEdit(); if (SpaceState.PHANTOM == mSpaceState && suggestion.length() > 0 // In the batch input mode, a manually picked suggested word should just replace diff --git a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt index 5ebc8fd8a..37e7b0e5b 100644 --- a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt +++ b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt @@ -398,6 +398,9 @@ public class LanguageModelFacilitator( wordComposer, values.inputStyle, true, -1, locale, suggestionResults, settingsValues.mAutoCorrectionThreshold) job.cancel() + + // TODO + if(values.sequenceId < currentSequenceId) return inputLogic.mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords) if(values.composedData.mIsBatchMode) { @@ -490,6 +493,11 @@ public class LanguageModelFacilitator( if(!inputLogic.mConnection.isConnected) return + if(ignoringNextUpdate) { + ignoringNextUpdate = false + return + } + try { val wordComposer = inputLogic.mWordComposer val ngramContext = inputLogic.getNgramContextFromNthPreviousWordForSuggestion( @@ -621,5 +629,11 @@ public class LanguageModelFacilitator( public fun onStartInput() { transformerDisabled = false numConsecutiveTimeouts = 0 + ignoringNextUpdate = false + } + + var ignoringNextUpdate = false + fun ignoreNextUpdate() { + ignoringNextUpdate = true } } \ No newline at end of file