Skip to content

Commit bfbaa57

Browse files
committed
fix(input): preserve sTimerProxy and sListener across trimMemory and revert input logic regressions
1 parent 2fd99a7 commit bfbaa57

3 files changed

Lines changed: 19 additions & 26 deletions

File tree

app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,22 @@ public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
8888
public static void clearOldViewData() {
8989
sProxyMap.clear();
9090
sDrawingProxy = null;
91-
sTimerProxy = TimerProxy.NULL;
92-
sListener = KeyboardActionListener.EMPTY_LISTENER;
91+
// Don't clear sTimerProxy or sListener here.
92+
// The MainKeyboardView (and its TimerHandler + ActionListener)
93+
// survives trimMemory(). These are only properly re-initialized
94+
// by init() and setKeyboardActionListener() during onCreateInputView().
9395
}
9496

9597
public static void switchTo(DrawingProxy drawingProxy) {
9698
if (drawingProxy == null) return;
9799
sDrawingProxy = drawingProxy;
98100
final Object[] thatArray = sProxyMap.get(drawingProxy);
99-
if (thatArray == null) {
100-
sTimerProxy = TimerProxy.NULL;
101-
return;
102-
}
101+
if (thatArray == null) return;
103102
sParams = (PointerTrackerParams) thatArray[0];
104103
sGestureStrokeRecognitionParams = (GestureStrokeRecognitionParams) thatArray[1];
105104
sGestureStrokeDrawingParams = (GestureStrokeDrawingParams) thatArray[2];
106105
sTypingTimeRecorder = (TypingTimeRecorder) thatArray[3];
107-
final TimerProxy timerProxy = (TimerProxy) thatArray[4];
108-
sTimerProxy = timerProxy != null ? timerProxy : TimerProxy.NULL;
106+
sTimerProxy = (TimerProxy) thatArray[4];
109107
// noinspection unchecked
110108
sTrackers = (ArrayList<PointerTracker>) thatArray[5];
111109
}

app/src/main/java/helium314/keyboard/latin/RichInputConnection.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ public boolean hasSlowInputConnection() {
173173

174174
public void onStartInput() {
175175
mLastSlowInputConnectionTime = -SLOW_INPUTCONNECTION_PERSIST_MS;
176-
mIC = mParent.getCurrentInputConnection();
177-
}
178-
179-
public void onFinishInput() {
180-
mIC = null;
181176
}
182177

183178
private void checkConsistencyForDebug() {
@@ -379,11 +374,13 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
379374
if (DebugFlags.DEBUG_ENABLED)
380375
Log.d(TAG, "committing " + text.length() + " characters");
381376
mCommittedTextBeforeComposingText.append(text);
382-
if (mExpectedSelStart == INVALID_CURSOR_POSITION) {
383-
mExpectedSelStart = text.length();
384-
} else {
385-
mExpectedSelStart += text.length() - mComposingText.length();
386-
}
377+
// TODO: the following is exceedingly error-prone. Right now when the cursor is
378+
// in the
379+
// middle of the composing word mComposingText only holds the part of the
380+
// composing text
381+
// that is before the cursor, so this actually works, but it's terribly
382+
// confusing. Fix this.
383+
mExpectedSelStart += text.length() - mComposingText.length();
387384
mExpectedSelEnd = mExpectedSelStart;
388385
mComposingText.setLength(0);
389386
if (isConnected()) {
@@ -395,6 +392,10 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
395392
final int spanStart = mTempObjectForCommitText.getSpanStart(span);
396393
final int spanEnd = mTempObjectForCommitText.getSpanEnd(span);
397394
final int spanFlags = mTempObjectForCommitText.getSpanFlags(span);
395+
// We have to adjust the end of the span to include an additional character.
396+
// This is to avoid splitting a unicode surrogate pair.
397+
// See helium314.keyboard.latin.common.Constants.UnicodeSurrogate
398+
// See https://b.corp.google.com/issues/19255233
398399
if (0 < spanEnd && spanEnd < mTempObjectForCommitText.length()) {
399400
final char spanEndChar = mTempObjectForCommitText.charAt(spanEnd - 1);
400401
final char nextChar = mTempObjectForCommitText.charAt(spanEnd);
@@ -404,8 +405,7 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
404405
}
405406
}
406407
}
407-
final CharSequence textToCommit = spans.length > 0 ? mTempObjectForCommitText : text.toString();
408-
mIC.commitText(textToCommit, newCursorPosition);
408+
mIC.commitText(mTempObjectForCommitText, newCursorPosition);
409409
}
410410
}
411411

@@ -867,11 +867,7 @@ public boolean setComposingText(final CharSequence text, final int newCursorPosi
867867
checkBatchEdit();
868868
if (DEBUG_PREVIOUS_TEXT)
869869
checkConsistencyForDebug();
870-
if (mExpectedSelStart == INVALID_CURSOR_POSITION) {
871-
mExpectedSelStart = text.length();
872-
} else {
873-
mExpectedSelStart += text.length() - mComposingText.length();
874-
}
870+
mExpectedSelStart += text.length() - mComposingText.length();
875871
mExpectedSelEnd = mExpectedSelStart;
876872
mComposingText.setLength(0);
877873
mComposingText.append(text);

app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ public void finishInput() {
252252
resetComposingState(true);
253253
mInputLogicHandler.reset();
254254
mSpaceState = SpaceState.NONE;
255-
mConnection.onFinishInput();
256255
}
257256

258257
/**

0 commit comments

Comments
 (0)