select keys can now de-select text (#973)

This commit is contained in:
Devy Ballard 2024-07-12 14:35:23 -06:00 committed by GitHub
parent b9e116ed13
commit 544132974c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -1761,7 +1761,7 @@ public class LatinIME extends InputMethodService implements
return;
break;
case KeyCode.ARROW_RIGHT, KeyCode.ARROW_DOWN, KeyCode.WORD_RIGHT, KeyCode.PAGE_DOWN:
if (!mInputLogic.mConnection.canForwardDeleteCharacters())
if (mInputLogic.mConnection.noTextAfterCursor())
return;
break;
}

View file

@ -363,9 +363,9 @@ public final class RichInputConnection implements PrivateCommandPerformer {
return mExpectedSelStart > 0;
}
public boolean canForwardDeleteCharacters() {
public boolean noTextAfterCursor() {
final CharSequence after = getTextAfterCursor(1, 0);
return !TextUtils.isEmpty(after);
return TextUtils.isEmpty(after);
}
/**
@ -728,12 +728,17 @@ public final class RichInputConnection implements PrivateCommandPerformer {
public void selectAll() {
if (!isConnected()) return;
mIC.performContextMenuAction(android.R.id.selectAll);
if (mExpectedSelStart != mExpectedSelEnd && mExpectedSelStart == 0 && noTextAfterCursor()) { // all text already selected
mIC.setSelection(mExpectedSelEnd, mExpectedSelEnd);
} else mIC.performContextMenuAction(android.R.id.selectAll);
}
public void selectWord(final SpacingAndPunctuations spacingAndPunctuations, final String script) {
if (!isConnected()) return;
if (mExpectedSelStart != mExpectedSelEnd) return; // already something selected
if (mExpectedSelStart != mExpectedSelEnd) { // already something selected
mIC.setSelection(mExpectedSelEnd, mExpectedSelEnd);
return;
}
final TextRange range = getWordRangeAtCursor(spacingAndPunctuations, script);
if (range == null) return;
mIC.setSelection(mExpectedSelStart - range.getNumberOfCharsInWordBeforeCursor(), mExpectedSelStart + range.getNumberOfCharsInWordAfterCursor());