more workarounds for Korean

not just space might delete text, but also other separators
now this problem is avoided in a more generic way
fixes GH-1447
This commit is contained in:
Helium314 2025-04-27 18:59:29 +02:00
parent 9c727f342d
commit 1d441a8ca6
3 changed files with 35 additions and 13 deletions

View file

@ -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

View file

@ -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);

View file

@ -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")