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

@ -9,16 +9,17 @@ Might end up on F-Droid...
* Allow loading Glide typing library
* not included in the app, as there is no compatible open source library
* can be extracted from GApps packages (_swypelibs_), or downloaded [here](https://github.com/erkserkserks/openboard/tree/master/app/src/main/jniLibs)
* Multilingual typing
* 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)
* additional dictionaries for emojis or scientific symbols can be used to provide suggestions ("emoji search")
* Adjust keyboard themes (style and colors)
* can follow the system's day/night setting
* Split keyboard
* Number row
* Number pad
* Show all available extra characters on long pressing a key
* Multilingual typing
* 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)
* 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)
* can follow the system's day/night setting
* Split keyboard
* Number row
* Number pad
* Show all available extra characters on long pressing a key
## Important differences and changes to OpenBoard
* Debug version can be installed along OpenBoard

View file

@ -2,7 +2,6 @@ package org.dslul.openboard.inputmethod.event
import android.text.SpannableStringBuilder
import android.text.TextUtils
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher
import org.dslul.openboard.inputmethod.latin.common.Constants
import java.util.*
@ -24,6 +23,19 @@ class CombinerChain(initialText: String) {
// The feedback on the composing state, as described above
private val mStateFeedback = SpannableStringBuilder()
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.
@ -43,15 +55,6 @@ class CombinerChain(initialText: String) {
fun reset() {
mCombinedText.setLength(0)
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) {
c.reset()
}

View file

@ -21,6 +21,8 @@ import androidx.annotation.NonNull;
import org.dslul.openboard.inputmethod.annotations.UsedForTesting;
import org.dslul.openboard.inputmethod.event.CombinerChain;
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.common.ComposedData;
import org.dslul.openboard.inputmethod.latin.common.Constants;
@ -91,6 +93,11 @@ public final class WordComposer {
mCursorPositionWithinWord = 0;
mRejectedBatchModeSuggestion = null;
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() {
@ -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.
*/
@ -274,8 +284,7 @@ public final class WordComposer {
final int codePoint = Character.codePointAt(word, i);
// We don't want to override the batch input points that are held in mInputPointers
// (See {@link #add(int,int,int)}).
final Event processedEvent =
processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
final Event processedEvent = processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
applyProcessedEvent(processedEvent);
}
}
@ -292,8 +301,9 @@ public final class WordComposer {
for (int i = 0; i < length; ++i) {
final Event processedEvent =
processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
CoordinateUtils.xFromArray(coordinates, i),
CoordinateUtils.yFromArray(coordinates, i)));
CoordinateUtils.xFromArray(coordinates, i),
CoordinateUtils.yFromArray(coordinates, i))
);
applyProcessedEvent(processedEvent);
}
mIsResumed = true;

View file

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