Use the WordComposer to check if we are composing a word
...instead of the hard-to-understand mHasUncommittedTypedChars. This is possible because now the word composer is actually aware of commits. Change-Id: I36b664ce8402a280f801e87b9ebe161f416b0853main
parent
6ba5f0d341
commit
196d82cdd7
|
@ -933,7 +933,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// newly inserted punctuation.
|
// newly inserted punctuation.
|
||||||
mSpaceState = SPACE_STATE_NONE;
|
mSpaceState = SPACE_STATE_NONE;
|
||||||
}
|
}
|
||||||
if (((mWordComposer.size() > 0 && mHasUncommittedTypedChars)
|
if (((mWordComposer.isComposingWord())
|
||||||
|| mVoiceProxy.isVoiceInputHighlighted())
|
|| mVoiceProxy.isVoiceInputHighlighted())
|
||||||
&& (selectionChanged || candidatesCleared)) {
|
&& (selectionChanged || candidatesCleared)) {
|
||||||
mWordComposer.reset();
|
mWordComposer.reset();
|
||||||
|
@ -945,7 +945,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
mComposingStateManager.onFinishComposingText();
|
mComposingStateManager.onFinishComposingText();
|
||||||
mVoiceProxy.setVoiceInputHighlighted(false);
|
mVoiceProxy.setVoiceInputHighlighted(false);
|
||||||
} else if (!mHasUncommittedTypedChars) {
|
} else if (!mWordComposer.isComposingWord()) {
|
||||||
updateSuggestions();
|
updateSuggestions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1146,7 +1146,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commitTyped(final InputConnection ic) {
|
public void commitTyped(final InputConnection ic) {
|
||||||
if (!mHasUncommittedTypedChars) return;
|
if (!mWordComposer.isComposingWord()) return;
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
final CharSequence typedWord = mWordComposer.getTypedWord();
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
||||||
mWordComposer.onCommitWord();
|
mWordComposer.onCommitWord();
|
||||||
|
@ -1422,18 +1422,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHasUncommittedTypedChars) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
final int length = mWordComposer.size();
|
final int length = mWordComposer.size();
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
mWordComposer.deleteLast();
|
mWordComposer.deleteLast();
|
||||||
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
||||||
if (mWordComposer.size() == 0) {
|
// If we have deleted the last remaining character of a word, then we are not
|
||||||
|
// isComposingWord() any more.
|
||||||
|
if (!mWordComposer.isComposingWord()) {
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
// Remaining size equals zero means we just erased the last character of the
|
// Not composing word any more, so we can show bigrams.
|
||||||
// word, so we can show bigrams.
|
|
||||||
mHandler.postUpdateBigramPredictions();
|
mHandler.postUpdateBigramPredictions();
|
||||||
} else {
|
} else {
|
||||||
// length > 1, so we still have letters to deduce a suggestion from.
|
// Still composing a word, so we still have letters to deduce a suggestion from.
|
||||||
mHandler.postUpdateSuggestions();
|
mHandler.postUpdateSuggestions();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1522,7 +1523,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
if (null != ic) removeTrailingSpaceWhileInBatchEdit(ic);
|
if (null != ic) removeTrailingSpaceWhileInBatchEdit(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isComposingWord = mHasUncommittedTypedChars;
|
boolean isComposingWord = mWordComposer.isComposingWord();
|
||||||
int code = primaryCode;
|
int code = primaryCode;
|
||||||
if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code))
|
if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code))
|
||||||
&& isSuggestionsRequested() && !isCursorTouchingWord()) {
|
&& isSuggestionsRequested() && !isCursorTouchingWord()) {
|
||||||
|
@ -1605,7 +1606,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// Reset the saved word in all cases. If this separator causes an autocorrection,
|
// Reset the saved word in all cases. If this separator causes an autocorrection,
|
||||||
// it will overwrite this null with the actual word we need to save.
|
// it will overwrite this null with the actual word we need to save.
|
||||||
mWordSavedForAutoCorrectCancellation = null;
|
mWordSavedForAutoCorrectCancellation = null;
|
||||||
if (mHasUncommittedTypedChars) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
// In certain languages where single quote is a separator, it's better
|
// In certain languages where single quote is a separator, it's better
|
||||||
// not to auto correct, but accept the typed word. For instance,
|
// not to auto correct, but accept the typed word. For instance,
|
||||||
// in Italian dov' should not be expanded to dove' because the elision
|
// in Italian dov' should not be expanded to dove' because the elision
|
||||||
|
@ -1780,7 +1781,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
mHandler.cancelUpdateSuggestions();
|
mHandler.cancelUpdateSuggestions();
|
||||||
mHandler.cancelUpdateBigramPredictions();
|
mHandler.cancelUpdateBigramPredictions();
|
||||||
|
|
||||||
if (!mHasUncommittedTypedChars) {
|
if (!mWordComposer.isComposingWord()) {
|
||||||
setPunctuationSuggestions();
|
setPunctuationSuggestions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1953,11 +1954,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!mHasUncommittedTypedChars) {
|
|
||||||
// If we are not composing a word, then it was a suggestion inferred from
|
|
||||||
// context - no user input. We should reset the word composer.
|
|
||||||
mWordComposer.reset();
|
|
||||||
}
|
|
||||||
mExpectingUpdateSelection = true;
|
mExpectingUpdateSelection = true;
|
||||||
commitBestWord(suggestion);
|
commitBestWord(suggestion);
|
||||||
// Add the word to the auto dictionary if it's not a known word
|
// Add the word to the auto dictionary if it's not a known word
|
||||||
|
@ -1967,8 +1963,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
} else {
|
} else {
|
||||||
addToOnlyBigramDictionary(suggestion, 1);
|
addToOnlyBigramDictionary(suggestion, 1);
|
||||||
}
|
}
|
||||||
// TODO: the following is fishy, because if !mHasUncommittedTypedChars we are
|
// TODO: the following is fishy, because it seems there may be cases where we are not
|
||||||
// going to log an empty string
|
// composing a word at all. Maybe throw an exception if !mWordComposer.isComposingWord() ?
|
||||||
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
|
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
|
||||||
suggestion.toString(), index, suggestions.mWords);
|
suggestion.toString(), index, suggestions.mWords);
|
||||||
// Follow it with a space
|
// Follow it with a space
|
||||||
|
|
|
@ -120,6 +120,10 @@ public class WordComposer {
|
||||||
return mCurrentWord.mTypedWord.length();
|
return mCurrentWord.mTypedWord.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isComposingWord() {
|
||||||
|
return size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the codes at a particular position in the word.
|
* Returns the codes at a particular position in the word.
|
||||||
* @param index the position in the word
|
* @param index the position in the word
|
||||||
|
|
Loading…
Reference in New Issue