mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "[AC7] Actually auto-commit."
This commit is contained in:
commit
7e51989b3f
@ -186,7 +186,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||
// flags too and pass mOutputTypes[j] instead of kind
|
||||
suggestions.add(new SuggestedWordInfo(new String(mOutputCodePoints, start, len),
|
||||
score, kind, this /* sourceDict */,
|
||||
mSpaceIndices[0] /* indexOfTouchPointOfSecondWord */,
|
||||
mSpaceIndices[j] /* indexOfTouchPointOfSecondWord */,
|
||||
mOutputAutoCommitFirstWordConfidence[0]));
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,17 @@ public final class InputPointers {
|
||||
mTimes.append(times, startPos, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift to the left by elementCount, discarding elementCount pointers at the start.
|
||||
* @param elementCount how many elements to shift.
|
||||
*/
|
||||
public void shift(final int elementCount) {
|
||||
mXCoordinates.shift(elementCount);
|
||||
mYCoordinates.shift(elementCount);
|
||||
mPointerIds.shift(elementCount);
|
||||
mTimes.shift(elementCount);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
final int defaultCapacity = mDefaultCapacity;
|
||||
mXCoordinates.reset(defaultCapacity);
|
||||
|
@ -1847,10 +1847,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|
||||
@Override
|
||||
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
||||
final SuggestedWordInfo candidate = mSuggestedWords.getAutoCommitCandidate();
|
||||
if (null != candidate) {
|
||||
if (candidate.mSourceDict.shouldAutoCommit(candidate)) {
|
||||
// TODO: implement auto-commit
|
||||
if (mSettings.getCurrent().mPhraseGestureEnabled) {
|
||||
final SuggestedWordInfo candidate = mSuggestedWords.getAutoCommitCandidate();
|
||||
if (null != candidate) {
|
||||
if (candidate.mSourceDict.shouldAutoCommit(candidate)) {
|
||||
final String[] commitParts = candidate.mWord.split(" ", 2);
|
||||
batchPointers.shift(candidate.mIndexOfTouchPointOfSecondWord);
|
||||
promotePhantomSpace();
|
||||
mConnection.commitText(commitParts[0], 0);
|
||||
mSpaceState = SPACE_STATE_PHANTOM;
|
||||
mKeyboardSwitcher.updateShiftState();
|
||||
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
|
||||
}
|
||||
}
|
||||
}
|
||||
mInputUpdater.onUpdateBatchInput(batchPointers);
|
||||
@ -1863,12 +1871,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
if (TextUtils.isEmpty(batchInputText)) {
|
||||
return;
|
||||
}
|
||||
mWordComposer.setBatchInputWord(batchInputText);
|
||||
mConnection.beginBatchEdit();
|
||||
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
||||
promotePhantomSpace();
|
||||
}
|
||||
mConnection.setComposingText(batchInputText, 1);
|
||||
if (mSettings.getCurrent().mPhraseGestureEnabled) {
|
||||
// Find the last space
|
||||
final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
|
||||
if (0 != indexOfLastSpace) {
|
||||
mConnection.commitText(batchInputText.substring(0, indexOfLastSpace), 1);
|
||||
}
|
||||
final String lastWord = batchInputText.substring(indexOfLastSpace);
|
||||
mWordComposer.setBatchInputWord(lastWord);
|
||||
mConnection.setComposingText(lastWord, 1);
|
||||
} else {
|
||||
mWordComposer.setBatchInputWord(batchInputText);
|
||||
mConnection.setComposingText(batchInputText, 1);
|
||||
}
|
||||
mExpectingUpdateSelection = true;
|
||||
mConnection.endBatchEdit();
|
||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||
|
@ -132,6 +132,15 @@ public final class ResizableIntArray {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift to the left by elementCount, discarding elementCount pointers at the start.
|
||||
* @param elementCount how many elements to shift.
|
||||
*/
|
||||
public void shift(final int elementCount) {
|
||||
System.arraycopy(mArray, elementCount, mArray, 0, mLength - elementCount);
|
||||
mLength -= elementCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
@ -244,4 +244,20 @@ public class InputPointersTests extends AndroidTestCase {
|
||||
expecteds[i + expectedPos], actuals[i + actualPos]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testShift() {
|
||||
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
||||
final int limit = 100;
|
||||
final int shiftAmount = 20;
|
||||
for (int i = 0; i < limit; i++) {
|
||||
src.addPointer(i, i * 2, i * 3, i * 4);
|
||||
}
|
||||
src.shift(shiftAmount);
|
||||
for (int i = 0; i < limit - shiftAmount; ++i) {
|
||||
assertEquals("xCoordinates at " + i, i + shiftAmount, src.getXCoordinates()[i]);
|
||||
assertEquals("yCoordinates at " + i, (i + shiftAmount) * 2, src.getYCoordinates()[i]);
|
||||
assertEquals("pointerIds at " + i, (i + shiftAmount) * 3, src.getPointerIds()[i]);
|
||||
assertEquals("times at " + i, (i + shiftAmount) * 4, src.getTimes()[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,4 +340,18 @@ public class ResizableIntArrayTests extends AndroidTestCase {
|
||||
expecteds[i + expectedPos], actuals[i + actualPos]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testShift() {
|
||||
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
|
||||
final int limit = DEFAULT_CAPACITY * 10;
|
||||
final int shiftAmount = 20;
|
||||
for (int i = 0; i < limit; ++i) {
|
||||
src.add(i, i);
|
||||
assertEquals("length after add at " + i, i + 1, src.getLength());
|
||||
}
|
||||
src.shift(shiftAmount);
|
||||
for (int i = 0; i < limit - shiftAmount; ++i) {
|
||||
assertEquals("value at " + i, i + shiftAmount, src.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user