fix hangul issue, some formatting

This commit is contained in:
Helium314 2023-09-17 22:00:06 +02:00
parent c4781e3da0
commit c7751423a1
2 changed files with 27 additions and 19 deletions

View file

@ -185,13 +185,20 @@ public final class WordComposer {
* @param event the event to apply. Must not be null. * @param event the event to apply. Must not be null.
*/ */
public void applyProcessedEvent(final Event event) { public void applyProcessedEvent(final Event event) {
applyProcessedEvent(event, false);
}
// specifically for that Constants.CODE_OUTPUT_TEXT Hangul event: try keeping cursor position
// because typically nothing changes, todo: if really nothing changes maybe there is a better way to do it
public void applyProcessedEvent(final Event event, final boolean keepCursorPosition) {
mCombinerChain.applyProcessedEvent(event); mCombinerChain.applyProcessedEvent(event);
final int primaryCode = event.getMCodePoint(); final int primaryCode = event.getMCodePoint();
final int keyX = event.getMX(); final int keyX = event.getMX();
final int keyY = event.getMY(); final int keyY = event.getMY();
final int newIndex = size(); final int newIndex = size();
refreshTypedWordCache(); refreshTypedWordCache();
mCursorPositionWithinWord = mCodePointSize; if (!keepCursorPosition || newIndex == mCodePointSize)
mCursorPositionWithinWord = mCodePointSize;
// We may have deleted the last one. // We may have deleted the last one.
if (0 == mCodePointSize) { if (0 == mCodePointSize) {
mIsOnlyFirstCharCapitalized = false; mIsOnlyFirstCharCapitalized = false;

View file

@ -441,7 +441,9 @@ public final class InputLogic {
if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL
// only use the Hangul chain if codepoint may actually be Hangul // only use the Hangul chain if codepoint may actually be Hangul
// todo: this whole hangul-related logic should probably be somewhere else // todo: this whole hangul-related logic should probably be somewhere else
&& event.getMCodePoint() >= 0x1100) { // need to use hangul combiner for whitespace, because otherwise the current word
// seems to get deleted / replaced by space during mConnection.endBatchEdit()
&& (event.getMCodePoint() >= 0x1100 || Character.isWhitespace(event.getMCodePoint()))) {
mWordComposer.setHangul(true); mWordComposer.setHangul(true);
final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event); final Event hangulDecodedEvent = HangulEventDecoder.decodeSoftwareKeyEvent(event);
processedEvent = mWordComposer.processEvent(hangulDecodedEvent); processedEvent = mWordComposer.processEvent(hangulDecodedEvent);
@ -739,9 +741,10 @@ public final class InputLogic {
inputTransaction.setDidAffectContents(); inputTransaction.setDidAffectContents();
break; break;
case Constants.CODE_OUTPUT_TEXT: case Constants.CODE_OUTPUT_TEXT:
// added in the hangul branch, but without this a space after a period crashes // added in the hangul branch, createEventChainFromSequence
// -> where is the change? // this introduces issues like space being added behind cursor, or input deleting
mWordComposer.applyProcessedEvent(event); // a word, but the keepCursorPosition applyProcessedEvent seems to help here
mWordComposer.applyProcessedEvent(event, true);
break; break;
case Constants.CODE_START_ONE_HANDED_MODE: case Constants.CODE_START_ONE_HANDED_MODE:
case Constants.CODE_STOP_ONE_HANDED_MODE: case Constants.CODE_STOP_ONE_HANDED_MODE:
@ -1494,8 +1497,7 @@ public final class InputLogic {
ngramContext, timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive); ngramContext, timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive);
} }
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, final int inputStyle) {
final int inputStyle) {
long startTimeMillis = 0; long startTimeMillis = 0;
if (DebugFlags.DEBUG_ENABLED) { if (DebugFlags.DEBUG_ENABLED) {
startTimeMillis = System.currentTimeMillis(); startTimeMillis = System.currentTimeMillis();
@ -1563,15 +1565,15 @@ public final class InputLogic {
// recorrection. This is a temporary, stopgap measure that will be removed later. // recorrection. This is a temporary, stopgap measure that will be removed later.
// TODO: remove this. // TODO: remove this.
if (!settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces if (!settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
// If no suggestions are requested, don't try restarting suggestions. // If no suggestions are requested, don't try restarting suggestions.
|| !settingsValues.needsToLookupSuggestions() || !settingsValues.needsToLookupSuggestions()
// If we are currently in a batch input, we must not resume suggestions, or the result // If we are currently in a batch input, we must not resume suggestions, or the result
// of the batch input will replace the new composition. This may happen in the corner case // of the batch input will replace the new composition. This may happen in the corner case
// that the app moves the cursor on its own accord during a batch input. // that the app moves the cursor on its own accord during a batch input.
|| mInputLogicHandler.isInBatchInput() || mInputLogicHandler.isInBatchInput()
// If the cursor is not touching a word, or if there is a selection, return right away. // If the cursor is not touching a word, or if there is a selection, return right away.
|| mConnection.hasSelection() || mConnection.hasSelection()
// If we don't know the cursor location, return. // If we don't know the cursor location, return.
|| mConnection.getExpectedSelectionStart() < 0) { || mConnection.getExpectedSelectionStart() < 0) {
mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
return; return;
@ -1585,12 +1587,13 @@ public final class InputLogic {
mConnection.finishComposingText(); mConnection.finishComposingText();
return; return;
} }
final TextRange range = mConnection.getWordRangeAtCursor( final TextRange range =
settingsValues.mSpacingAndPunctuations, currentKeyboardScriptId, true); mConnection.getWordRangeAtCursor(settingsValues.mSpacingAndPunctuations, currentKeyboardScriptId, true);
if (null == range) return; // Happens if we don't have an input connection at all if (null == range) return; // Happens if we don't have an input connection at all
if (range.length() <= 0) { if (range.length() <= 0) {
// Race condition, or touching a word in a non-supported script. // Race condition, or touching a word in a non-supported script.
mLatinIME.setNeutralSuggestionStrip(); mLatinIME.setNeutralSuggestionStrip();
mConnection.finishComposingText();
return; return;
} }
// If for some strange reason (editor bug or so) we measure the text before the cursor as // If for some strange reason (editor bug or so) we measure the text before the cursor as
@ -1631,10 +1634,8 @@ public final class InputLogic {
} }
} }
final int[] codePoints = StringUtils.toCodePointArray(typedWordString); final int[] codePoints = StringUtils.toCodePointArray(typedWordString);
mWordComposer.setComposingWord(codePoints, mWordComposer.setComposingWord(codePoints, mLatinIME.getCoordinatesForCurrentKeyboard(codePoints));
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints)); mWordComposer.setCursorPositionWithinWord(typedWordString.codePointCount(0, numberOfCharsInWordBeforeCursor));
mWordComposer.setCursorPositionWithinWord(
typedWordString.codePointCount(0, numberOfCharsInWordBeforeCursor));
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor, mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor()); expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
if (suggestions.size() <= 1) { if (suggestions.size() <= 1) {