am 763fd9d5: Merge "Fix revert of committed words"
* commit '763fd9d5e9a3136a4a7300219b8094df089fe5b6': Fix revert of committed wordsmain
commit
afbaac36a8
|
@ -83,6 +83,8 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
// TODO: Add a unit test for every "logging" method (i.e. that is called from the IME and calls
|
||||||
|
// enqueueEvent to record a LogStatement).
|
||||||
/**
|
/**
|
||||||
* Logs the use of the LatinIME keyboard.
|
* Logs the use of the LatinIME keyboard.
|
||||||
*
|
*
|
||||||
|
@ -1463,21 +1465,39 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static void latinIME_revertCommit(final String committedWord,
|
public static void latinIME_revertCommit(final String committedWord,
|
||||||
final String originallyTypedWord, final boolean isBatchMode,
|
final String originallyTypedWord, final boolean isBatchMode,
|
||||||
final String separatorString) {
|
final String separatorString) {
|
||||||
|
// TODO: Prioritize adding a unit test for this method (as it is especially complex)
|
||||||
|
// TODO: Update the UserRecording LogBuffer as well as the MainLogBuffer
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
// TODO: Verify that mCurrentLogUnit has been restored and contains the reverted word.
|
//
|
||||||
final LogUnit logUnit;
|
// 1. Remove separator LogUnit
|
||||||
logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit();
|
final LogUnit lastLogUnit = researchLogger.mMainLogBuffer.peekLastLogUnit();
|
||||||
if (originallyTypedWord.length() > 0 && hasLetters(originallyTypedWord)) {
|
// Check that we're not at the beginning of input
|
||||||
if (logUnit != null) {
|
if (lastLogUnit == null) return;
|
||||||
logUnit.setWords(originallyTypedWord);
|
// Check that we're after a separator
|
||||||
}
|
if (lastLogUnit.getWordsAsString() != null) return;
|
||||||
}
|
// Remove separator
|
||||||
researchLogger.enqueueEvent(logUnit != null ? logUnit : researchLogger.mCurrentLogUnit,
|
final LogUnit separatorLogUnit = researchLogger.mMainLogBuffer.unshiftIn();
|
||||||
LOGSTATEMENT_LATINIME_REVERTCOMMIT, committedWord, originallyTypedWord,
|
|
||||||
separatorString);
|
// 2. Add revert LogStatement
|
||||||
if (logUnit != null) {
|
final LogUnit revertedLogUnit = researchLogger.mMainLogBuffer.peekLastLogUnit();
|
||||||
logUnit.setContainsUserDeletions();
|
if (revertedLogUnit == null) return;
|
||||||
|
if (!revertedLogUnit.getWordsAsString().equals(scrubDigitsFromString(committedWord))) {
|
||||||
|
// Any word associated with the reverted LogUnit has already had its digits scrubbed, so
|
||||||
|
// any digits in the committedWord argument must also be scrubbed for an accurate
|
||||||
|
// comparison.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
researchLogger.enqueueEvent(revertedLogUnit, LOGSTATEMENT_LATINIME_REVERTCOMMIT,
|
||||||
|
committedWord, originallyTypedWord, separatorString);
|
||||||
|
|
||||||
|
// 3. Update the word associated with the LogUnit
|
||||||
|
revertedLogUnit.setWords(originallyTypedWord);
|
||||||
|
revertedLogUnit.setContainsUserDeletions();
|
||||||
|
|
||||||
|
// 4. Re-add the separator LogUnit
|
||||||
|
researchLogger.mMainLogBuffer.shiftIn(separatorLogUnit);
|
||||||
|
|
||||||
|
// 5. Record stats
|
||||||
researchLogger.mStatistics.recordRevertCommit(SystemClock.uptimeMillis());
|
researchLogger.mStatistics.recordRevertCommit(SystemClock.uptimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue