don't reload when moving cursor within a word using space bar gesture

gives performance improvement noticeable at least on slow phones
This commit is contained in:
Helium314 2023-10-17 20:57:02 +02:00
parent 78e924ee6d
commit ec1a91d1e0
3 changed files with 26 additions and 6 deletions

View file

@ -56,6 +56,8 @@ import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.CoordinateUtils;
import org.dslul.openboard.inputmethod.latin.common.InputPointers;
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
import org.dslul.openboard.inputmethod.latin.common.StringUtilsKt;
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
import org.dslul.openboard.inputmethod.latin.define.ProductionFlags;
import org.dslul.openboard.inputmethod.latin.inputlogic.InputLogic;
@ -1397,8 +1399,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// for RTL languages we want to invert pointer movement
if (mRichImm.getCurrentSubtype().isRtlSubtype())
steps = -steps;
mInputLogic.finishInput();
if (steps < 0) {
int availableCharacters = mInputLogic.mConnection.getTextBeforeCursor(64, 0).length();
steps = availableCharacters < -steps ? -availableCharacters : steps;
@ -1409,6 +1410,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else
return;
if (mInputLogic.moveCursorByAndReturnIfInsideComposingWord(steps)) {
// no need to finish input and restart suggestions if we're still in the word
// this is a noticeable performance improvement
int newPosition = mInputLogic.mConnection.mExpectedSelStart + steps;
mInputLogic.mConnection.setSelection(newPosition, newPosition);
return;
}
mInputLogic.finishInput();
int newPosition = mInputLogic.mConnection.mExpectedSelStart + steps;
mInputLogic.mConnection.setSelection(newPosition, newPosition);
mInputLogic.restartSuggestionsOnWordTouchedByCursor(mSettings.getCurrent(), mKeyboardSwitcher.getCurrentKeyboardScriptId());

View file

@ -241,6 +241,10 @@ public final class RichInputConnection implements PrivateCommandPerformer {
*/
private boolean reloadTextCache() {
mCommittedTextBeforeComposingText.setLength(0);
// Clearing composing text was not in original AOSP and OpenBoard, but why? should actually
// be necessary when reloading text. Only when called by setSelection, mComposingText isn't
// always empty, but looks like things still work normally
mComposingText.setLength(0);
mIC = mParent.getCurrentInputConnection();
// Call upon the inputconnection directly since our own method is using the cache, and
// we want to refresh it.
@ -382,14 +386,17 @@ public final class RichInputConnection implements PrivateCommandPerformer {
spacingAndPunctuations, hasSpaceBefore);
}
public int getCodePointBeforeCursor() {
final int length = mCommittedTextBeforeComposingText.length();
public int getCodePointBeforeCursor() { // todo: behavior still correct? also should do this to getCharBeforeBeforeCursor
final CharSequence text = mComposingText.length() == 0 ? mCommittedTextBeforeComposingText : mComposingText;
final int length = text.length();
if (length < 1) return Constants.NOT_A_CODE;
return Character.codePointBefore(mCommittedTextBeforeComposingText, length);
return Character.codePointBefore(text, length);
}
public int getCharBeforeBeforeCursor() {
public int getCharBeforeBeforeCursor() { // todo: behavior still correct?
if (mComposingText.length() >= 2) return mComposingText.charAt(mComposingText.length() - 2);
final int length = mCommittedTextBeforeComposingText.length();
if (mComposingText.length() == 1) return mCommittedTextBeforeComposingText.charAt(length - 1);
if (length < 2) return Constants.NOT_A_CODE;
return mCommittedTextBeforeComposingText.charAt(length - 2);
}

View file

@ -409,6 +409,10 @@ public final class InputLogic {
return true;
}
public boolean moveCursorByAndReturnIfInsideComposingWord(int distance) {
return mWordComposer.moveCursorByAndReturnIfInsideComposingWord(distance);
}
/**
* React to a code input. It may be a code point to insert, or a symbolic value that influences
* the keyboard behavior.