fix the combiner chain issue

This commit is contained in:
Helium314 2023-09-16 09:19:47 +02:00
parent 7bd960e1a7
commit a7fdf6c700
5 changed files with 40 additions and 24 deletions

View file

@ -13,6 +13,7 @@ Might end up on F-Droid...
* Load external dictionaries * Load external dictionaries
* get them [here](https://codeberg.org/Helium314/aosp-dictionaries/src/branch/main/dictionaries), or in the [experimental](https://codeberg.org/Helium314/aosp-dictionaries/src/branch/main/dictionaries_experimental) section (quality may vary) * get them [here](https://codeberg.org/Helium314/aosp-dictionaries/src/branch/main/dictionaries), or in the [experimental](https://codeberg.org/Helium314/aosp-dictionaries/src/branch/main/dictionaries_experimental) section (quality may vary)
* additional dictionaries for emojis or scientific symbols can be used to provide suggestions ("emoji search") * additional dictionaries for emojis or scientific symbols can be used to provide suggestions ("emoji search")
* note that for Korean layouts, suggestions only work using [this dictionary](https://github.com/openboard-team/openboard/commit/83fca9533c03b9fecc009fc632577226bbd6301f), the tools in the dictionary repository are not able to create working dictionaries
* Adjust keyboard themes (style and colors) * Adjust keyboard themes (style and colors)
* can follow the system's day/night setting * can follow the system's day/night setting
* Split keyboard * Split keyboard

View file

@ -2,7 +2,6 @@ package org.dslul.openboard.inputmethod.event
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.TextUtils import android.text.TextUtils
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher
import org.dslul.openboard.inputmethod.latin.common.Constants import org.dslul.openboard.inputmethod.latin.common.Constants
import java.util.* import java.util.*
@ -24,6 +23,19 @@ class CombinerChain(initialText: String) {
// The feedback on the composing state, as described above // The feedback on the composing state, as described above
private val mStateFeedback = SpannableStringBuilder() private val mStateFeedback = SpannableStringBuilder()
private val mCombiners = ArrayList<Combiner>() private val mCombiners = ArrayList<Combiner>()
// Hangul combiner affects other scripts, e.g. period is seen as port of a word for latin,
// so we need to remove the combiner when not writing in hangul script.
// Maybe it would be better to always have the Hangul combiner, but make sure it doesn't affect
// events for other scripts, but how?
var isHangul = false
set(value) {
if (field == value) return
field = value
if (!value)
mCombiners.removeAll { it is HangulCombiner }
else if (mCombiners.none { it is HangulCombiner })
mCombiners.add(HangulCombiner())
}
/** /**
* Create an combiner chain. * Create an combiner chain.
@ -43,15 +55,6 @@ class CombinerChain(initialText: String) {
fun reset() { fun reset() {
mCombinedText.setLength(0) mCombinedText.setLength(0)
mStateFeedback.clear() mStateFeedback.clear()
// todo: the first word after language switch is still affected
if (KeyboardSwitcher.getInstance().keyboard?.mId?.mSubtype?.locale?.language == "ko") {
// if the hangul combiner is added for other keyboards, it leads to weird behavior,
// e.g. for latin script, period is seen as part of a word
if (mCombiners.none { it is HangulCombiner })
mCombiners.add(HangulCombiner())
} else {
mCombiners.removeAll { it is HangulCombiner }
}
for (c in mCombiners) { for (c in mCombiners) {
c.reset() c.reset()
} }

View file

@ -21,6 +21,8 @@ import androidx.annotation.NonNull;
import org.dslul.openboard.inputmethod.annotations.UsedForTesting; import org.dslul.openboard.inputmethod.annotations.UsedForTesting;
import org.dslul.openboard.inputmethod.event.CombinerChain; import org.dslul.openboard.inputmethod.event.CombinerChain;
import org.dslul.openboard.inputmethod.event.Event; import org.dslul.openboard.inputmethod.event.Event;
import org.dslul.openboard.inputmethod.keyboard.Keyboard;
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher;
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import org.dslul.openboard.inputmethod.latin.common.ComposedData; import org.dslul.openboard.inputmethod.latin.common.ComposedData;
import org.dslul.openboard.inputmethod.latin.common.Constants; import org.dslul.openboard.inputmethod.latin.common.Constants;
@ -91,6 +93,11 @@ public final class WordComposer {
mCursorPositionWithinWord = 0; mCursorPositionWithinWord = 0;
mRejectedBatchModeSuggestion = null; mRejectedBatchModeSuggestion = null;
refreshTypedWordCache(); refreshTypedWordCache();
final Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard();
if (keyboard != null)
// initializing with the right state is important for the spell checker,
// which creates a new WordComposer when receiving suggestions
mCombinerChain.setHangul(keyboard.mId.mSubtype.getLocale().getLanguage().equals("ko"));
} }
public ComposedData getComposedDataSnapshot() { public ComposedData getComposedDataSnapshot() {
@ -109,6 +116,9 @@ public final class WordComposer {
} }
} }
/** Forwards the state to CombinerChain, which disables or enables the Hangul combiner */
public void setHangul(final boolean enabled) { mCombinerChain.setHangul(enabled); }
/** /**
* Clear out the keys registered so far. * Clear out the keys registered so far.
*/ */
@ -274,8 +284,7 @@ public final class WordComposer {
final int codePoint = Character.codePointAt(word, i); final int codePoint = Character.codePointAt(word, i);
// We don't want to override the batch input points that are held in mInputPointers // We don't want to override the batch input points that are held in mInputPointers
// (See {@link #add(int,int,int)}). // (See {@link #add(int,int,int)}).
final Event processedEvent = final Event processedEvent = processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
applyProcessedEvent(processedEvent); applyProcessedEvent(processedEvent);
} }
} }
@ -293,7 +302,8 @@ public final class WordComposer {
final Event processedEvent = final Event processedEvent =
processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i], processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
CoordinateUtils.xFromArray(coordinates, i), CoordinateUtils.xFromArray(coordinates, i),
CoordinateUtils.yFromArray(coordinates, i))); CoordinateUtils.yFromArray(coordinates, i))
);
applyProcessedEvent(processedEvent); applyProcessedEvent(processedEvent);
} }
mIsResumed = true; mIsResumed = true;

View file

@ -449,9 +449,11 @@ public final class InputLogic {
mJustRevertedACommit = false; mJustRevertedACommit = false;
final Event processedEvent; final Event processedEvent;
if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL) { if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL) {
mWordComposer.setHangul(true);
final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event); final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event);
processedEvent = mWordComposer.processEvent(hangulDecodedEvent); processedEvent = mWordComposer.processEvent(hangulDecodedEvent);
} else { } else {
mWordComposer.setHangul(false);
processedEvent = mWordComposer.processEvent(event); processedEvent = mWordComposer.processEvent(event);
} }
final InputTransaction inputTransaction = new InputTransaction(settingsValues, final InputTransaction inputTransaction = new InputTransaction(settingsValues,