mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-02 21:04:28 +00:00
Use software string event for HangulCombiner composing word processing to fix auto spacing problem
This commit is contained in:
parent
1616c89bd4
commit
a5f773619b
4 changed files with 18 additions and 19 deletions
|
@ -206,6 +206,13 @@ class Event private constructor(// The type of event - one of the constants abov
|
||||||
null /* suggestedWordInfo */, FLAG_NONE, null /* next */)
|
null /* suggestedWordInfo */, FLAG_NONE, null /* next */)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun createSoftwareTextEvent(text: CharSequence?, keyCode: Int, next: Event): Event {
|
||||||
|
return Event(EVENT_TYPE_SOFTWARE_GENERATED_STRING, text, NOT_A_CODE_POINT, keyCode,
|
||||||
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
|
||||||
|
null /* suggestedWordInfo */, FLAG_NONE, next)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an input event representing the manual pick of a punctuation suggestion.
|
* Creates an input event representing the manual pick of a punctuation suggestion.
|
||||||
* @return an event for this suggestion pick.
|
* @return an event for this suggestion pick.
|
||||||
|
|
|
@ -43,9 +43,7 @@ class HangulCombiner : Combiner {
|
||||||
val currentSyllable = syllable ?: HangulSyllable()
|
val currentSyllable = syllable ?: HangulSyllable()
|
||||||
val jamo = HangulJamo.of(event.mCodePoint)
|
val jamo = HangulJamo.of(event.mCodePoint)
|
||||||
if(!event.isCombining || jamo is HangulJamo.NonHangul) {
|
if(!event.isCombining || jamo is HangulJamo.NonHangul) {
|
||||||
val text = combiningStateFeedback
|
composingWord.append(jamo.string)
|
||||||
reset()
|
|
||||||
return createEventChainFromSequence(text, event)
|
|
||||||
} else {
|
} else {
|
||||||
when(jamo) {
|
when(jamo) {
|
||||||
is HangulJamo.Consonant -> {
|
is HangulJamo.Consonant -> {
|
||||||
|
@ -316,19 +314,8 @@ class HangulCombiner : Combiner {
|
||||||
0x11b8 to 0x11ba to 0x11b9, // ㅄ
|
0x11b8 to 0x11ba to 0x11b9, // ㅄ
|
||||||
0x11ba to 0x11ba to 0x11bb // ㅆ
|
0x11ba to 0x11ba to 0x11bb // ㅆ
|
||||||
)
|
)
|
||||||
private fun createEventChainFromSequence(text: CharSequence, originalEvent: Event?): Event? {
|
private fun createEventChainFromSequence(text: CharSequence, originalEvent: Event): Event {
|
||||||
var index = text.length
|
return Event.createSoftwareTextEvent(text, Constants.CODE_OUTPUT_TEXT, originalEvent);
|
||||||
if (index <= 0) {
|
|
||||||
return originalEvent
|
|
||||||
}
|
|
||||||
var lastEvent: Event? = originalEvent
|
|
||||||
do {
|
|
||||||
val codePoint = Character.codePointBefore(text, index)
|
|
||||||
lastEvent = Event.Companion.createHardwareKeypressEvent(codePoint,
|
|
||||||
originalEvent!!.mKeyCode, lastEvent, false /* isKeyRepeat */)
|
|
||||||
index -= Character.charCount(codePoint)
|
|
||||||
} while (index > 0)
|
|
||||||
return lastEvent
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ public class KoreanDictionary extends Dictionary {
|
||||||
private String processInput(String input) {
|
private String processInput(String input) {
|
||||||
String normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
|
String normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
for(char c : normalized.toCharArray()) {
|
for (char c : normalized.toCharArray()) {
|
||||||
int index = COMPAT_JAMO.indexOf(c);
|
int index = COMPAT_JAMO.indexOf(c);
|
||||||
if(index == -1) result.append(c);
|
if (index == -1) result.append(c);
|
||||||
else result.append(STANDARD_JAMO.charAt(index));
|
else result.append(STANDARD_JAMO.charAt(index));
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
@ -43,7 +43,7 @@ public class KoreanDictionary extends Dictionary {
|
||||||
composedData = new ComposedData(composedData.mInputPointers, composedData.mIsBatchMode, processInput(composedData.mTypedWord));
|
composedData = new ComposedData(composedData.mInputPointers, composedData.mIsBatchMode, processInput(composedData.mTypedWord));
|
||||||
ArrayList<SuggestedWords.SuggestedWordInfo> suggestions = mDictionary.getSuggestions(composedData, ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId, weightForLocale, inOutWeightOfLangModelVsSpatialModel);
|
ArrayList<SuggestedWords.SuggestedWordInfo> suggestions = mDictionary.getSuggestions(composedData, ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId, weightForLocale, inOutWeightOfLangModelVsSpatialModel);
|
||||||
ArrayList<SuggestedWords.SuggestedWordInfo> result = new ArrayList<>();
|
ArrayList<SuggestedWords.SuggestedWordInfo> result = new ArrayList<>();
|
||||||
for(SuggestedWords.SuggestedWordInfo info : suggestions) {
|
for (SuggestedWords.SuggestedWordInfo info : suggestions) {
|
||||||
result.add(new SuggestedWords.SuggestedWordInfo(processOutput(info.mWord), info.mPrevWordsContext,
|
result.add(new SuggestedWords.SuggestedWordInfo(processOutput(info.mWord), info.mPrevWordsContext,
|
||||||
info.mScore, info.mKindAndFlags, info.mSourceDict, info.mIndexOfTouchPointOfSecondWord, info.mAutoCommitFirstWordConfidence));
|
info.mScore, info.mKindAndFlags, info.mSourceDict, info.mIndexOfTouchPointOfSecondWord, info.mAutoCommitFirstWordConfidence));
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,8 @@ public class KoreanDictionary extends Dictionary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean same(char[] word, int length, String typedWord) {
|
protected boolean same(char[] word, int length, String typedWord) {
|
||||||
|
word = processInput(new String(word)).toCharArray();
|
||||||
|
typedWord = processInput(typedWord);
|
||||||
return mDictionary.same(word, length, typedWord);
|
return mDictionary.same(word, length, typedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -702,6 +702,9 @@ public final class InputLogic {
|
||||||
// line, so that does affect the contents of the editor.
|
// line, so that does affect the contents of the editor.
|
||||||
inputTransaction.setDidAffectContents();
|
inputTransaction.setDidAffectContents();
|
||||||
break;
|
break;
|
||||||
|
case Constants.CODE_OUTPUT_TEXT:
|
||||||
|
mWordComposer.applyProcessedEvent(event);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown key code : " + event.getMKeyCode());
|
throw new RuntimeException("Unknown key code : " + event.getMKeyCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue