diff --git a/app/src/main/java/helium314/keyboard/latin/WordComposer.java b/app/src/main/java/helium314/keyboard/latin/WordComposer.java index 203eb205c..a5b50f353 100644 --- a/app/src/main/java/helium314/keyboard/latin/WordComposer.java +++ b/app/src/main/java/helium314/keyboard/latin/WordComposer.java @@ -218,6 +218,11 @@ public final class WordComposer { // TODO: compute where that puts us inside the events } + public void resetInvalidCursorPosition() { + if (mCursorPositionWithinWord > mCodePointSize) + mCursorPositionWithinWord = 0; + } + public boolean isCursorFrontOrMiddleOfComposingWord() { if (DebugFlags.DEBUG_ENABLED && mCursorPositionWithinWord > mCodePointSize) { throw new RuntimeException("Wrong cursor position : " + mCursorPositionWithinWord diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index 79464dee3..4b1bd4df2 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -440,19 +440,28 @@ public final class InputLogic { mWordBeingCorrectedByCursor = null; mJustRevertedACommit = false; final Event processedEvent; - if (currentKeyboardScript.equals(ScriptUtils.SCRIPT_HANGUL) - // only use the Hangul chain if codepoint may actually be Hangul - // todo: this whole hangul-related logic should probably be somewhere else - // need to use hangul combiner for whitespace, because otherwise the current word - // seems to get deleted / replaced by space during mConnection.endBatchEdit() - // similar for functional keys (codePoint -1) - && (event.getMCodePoint() >= 0x1100 || Character.isWhitespace(event.getMCodePoint()) || event.getMCodePoint() == -1)) { - mWordComposer.setHangul(true); - final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event); - // todo: here hangul combiner does already consume the event, and appends typed codepoint - // to the current word instead of considering the cursor position - // position is actually not visible to the combiner, how to fix? - processedEvent = mWordComposer.processEvent(hangulDecodedEvent); + if (currentKeyboardScript.equals(ScriptUtils.SCRIPT_HANGUL)) { + // only use the Hangul chain if codepoint may actually be Hangul + // todo: this whole hangul-related logic should probably be somewhere else + // need to use hangul combiner for functional keys (codePoint -1), because otherwise the current word + // seems to get deleted / replaced by space during mConnection.endBatchEdit() + if (event.getMCodePoint() >= 0x1100 || event.getMCodePoint() == -1) { + mWordComposer.setHangul(true); + final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event); + // todo: here hangul combiner does already consume the event, and appends typed codepoint + // to the current word instead of considering the cursor position + // position is actually not visible to the combiner, how to fix? + processedEvent = mWordComposer.processEvent(hangulDecodedEvent); + } else { + mWordComposer.setHangul(false); + final boolean wasComposingWord = mWordComposer.isComposingWord(); + processedEvent = mWordComposer.processEvent(event); + // workaround for space and some other separators deleting / replacing the word + if (wasComposingWord && !mWordComposer.isComposingWord()) { + mWordComposer.resetInvalidCursorPosition(); + mConnection.finishComposingText(); + } + } } else { mWordComposer.setHangul(false); processedEvent = mWordComposer.processEvent(event); diff --git a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt index 4f75173e5..1fd8dea0b 100644 --- a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt @@ -152,6 +152,14 @@ class InputLogicTest { assertEquals(4, cursor) } + // see issue 1447 + @Test fun separatorAfterHangul() { + reset() + currentScript = ScriptUtils.SCRIPT_HANGUL + chainInput("ㅛ.") + assertEquals("ㅛ.", text) + } + @Test fun separatorUnselectsWord() { reset() setText("hello")