am be2f81f0: Merge "Make the word composer aware of commits."

* commit 'be2f81f05539c064bdc1791d0dd60f3e68292ae1':
  Make the word composer aware of commits.
This commit is contained in:
Jean Chalard 2011-12-15 22:56:17 -08:00 committed by Android Git Automerger
commit 71551c2bc4
2 changed files with 29 additions and 6 deletions

View file

@ -1149,6 +1149,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mHasUncommittedTypedChars) return; if (!mHasUncommittedTypedChars) return;
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
final CharSequence typedWord = mWordComposer.getTypedWord(); final CharSequence typedWord = mWordComposer.getTypedWord();
mWordComposer.onCommitWord();
if (typedWord.length() > 0) { if (typedWord.length() > 0) {
if (ic != null) { if (ic != null) {
ic.commitText(typedWord, 1); ic.commitText(typedWord, 1);
@ -2033,6 +2034,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
} }
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
mWordComposer.onCommitWord();
} }
private static final WordComposer sEmptyWordComposer = new WordComposer(); private static final WordComposer sEmptyWordComposer = new WordComposer();
@ -2202,10 +2204,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
} }
ic.deleteSurroundingText(cancelLength + 1, 0); ic.deleteSurroundingText(cancelLength + 1, 0);
mWordComposer.resumeSuggestionOnKeptWord();
// Re-insert the separator
ic.commitText(mWordComposer.getTypedWord(), 1); ic.commitText(mWordComposer.getTypedWord(), 1);
// Re-insert the separator
ic.commitText(separator, 1); ic.commitText(separator, 1);
mWordComposer.onCommitWord();
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE, Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE); WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();
@ -2234,6 +2237,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving // restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving
// the old WordComposer allows to reuse the actual typed coordinates. // the old WordComposer allows to reuse the actual typed coordinates.
mHasUncommittedTypedChars = true; mHasUncommittedTypedChars = true;
mWordComposer.resumeSuggestionOnKeptWord();
ic.setComposingText(mWordComposer.getTypedWord(), 1); ic.setComposingText(mWordComposer.getTypedWord(), 1);
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions(); mHandler.postUpdateSuggestions();

View file

@ -61,11 +61,10 @@ public class WordComposer {
} }
} }
// The currently typing word. // The currently typing word. May not be null.
// NOTE: this is not reset as soon as the word is committed because it may be needed again
// to resume suggestion if backspaced. TODO: separate cleanly what is actually being
// composed and what is kept for possible resuming.
private CharacterStore mCurrentWord; private CharacterStore mCurrentWord;
// The information being kept for resuming suggestion. May be null if wiped.
private CharacterStore mWordKeptForSuggestionResuming;
// An auto-correction for this word out of the dictionary. // An auto-correction for this word out of the dictionary.
private CharSequence mAutoCorrection; private CharSequence mAutoCorrection;
@ -82,6 +81,7 @@ public class WordComposer {
public WordComposer() { public WordComposer() {
mCurrentWord = new CharacterStore(); mCurrentWord = new CharacterStore();
mWordKeptForSuggestionResuming = null;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
mAutoCorrection = null; mAutoCorrection = null;
} }
@ -92,6 +92,7 @@ public class WordComposer {
public void init(WordComposer source) { public void init(WordComposer source) {
mCurrentWord = new CharacterStore(source.mCurrentWord); mCurrentWord = new CharacterStore(source.mCurrentWord);
mWordKeptForSuggestionResuming = source.mWordKeptForSuggestionResuming;
mCapsCount = source.mCapsCount; mCapsCount = source.mCapsCount;
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized; mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
mAutoCapitalized = source.mAutoCapitalized; mAutoCapitalized = source.mAutoCapitalized;
@ -104,6 +105,7 @@ public class WordComposer {
*/ */
public void reset() { public void reset() {
mCurrentWord.reset(); mCurrentWord.reset();
mWordKeptForSuggestionResuming = null;
mCapsCount = 0; mCapsCount = 0;
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
@ -323,4 +325,21 @@ public class WordComposer {
public CharSequence getAutoCorrectionOrNull() { public CharSequence getAutoCorrectionOrNull() {
return mAutoCorrection; return mAutoCorrection;
} }
// TODO: pass the information about what was committed and how. Was it an auto-correction?
// Was it a completion? Was is what the user typed?
public void onCommitWord() {
mWordKeptForSuggestionResuming = mCurrentWord;
// TODO: improve performance by swapping buffers instead of creating a new object.
mCurrentWord = new CharacterStore();
}
public boolean hasWordKeptForSuggestionResuming() {
return null != mWordKeptForSuggestionResuming;
}
public void resumeSuggestionOnKeptWord() {
mCurrentWord = mWordKeptForSuggestionResuming;
mWordKeptForSuggestionResuming = null;
}
} }