diff --git a/README.md b/README.md index f6c9b3575..89d2f43ea 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/assets/dicts/main_ko.dict b/app/src/main/assets/dicts/main_ko.dict deleted file mode 100644 index 17e99020c..000000000 Binary files a/app/src/main/assets/dicts/main_ko.dict and /dev/null differ diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/event/CombinerChain.kt b/app/src/main/java/org/dslul/openboard/inputmethod/event/CombinerChain.kt index 0a1cae551..6cd5df09d 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/event/CombinerChain.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/event/CombinerChain.kt @@ -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() + // 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() } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java index 3e8efce6a..5f9ce3785 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java @@ -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; diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java index 19a073019..747415434 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java @@ -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,