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; return;
break; break;
case KeyCode.ARROW_RIGHT, KeyCode.ARROW_DOWN, KeyCode.WORD_RIGHT, KeyCode.PAGE_DOWN: case KeyCode.ARROW_RIGHT, KeyCode.ARROW_DOWN, KeyCode.WORD_RIGHT, KeyCode.PAGE_DOWN:
if (!mInputLogic.mConnection.canForwardDeleteCharacters()) if (mInputLogic.mConnection.noTextAfterCursor())
return; return;
break; break;
} }

View file

@ -363,9 +363,9 @@ public final class RichInputConnection implements PrivateCommandPerformer {
return mExpectedSelStart > 0; return mExpectedSelStart > 0;
} }
public boolean canForwardDeleteCharacters() { public boolean noTextAfterCursor() {
final CharSequence after = getTextAfterCursor(1, 0); 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() { public void selectAll() {
if (!isConnected()) return; 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) { public void selectWord(final SpacingAndPunctuations spacingAndPunctuations, final String script) {
if (!isConnected()) return; 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); final TextRange range = getWordRangeAtCursor(spacingAndPunctuations, script);
if (range == null) return; if (range == null) return;
mIC.setSelection(mExpectedSelStart - range.getNumberOfCharsInWordBeforeCursor(), mExpectedSelStart + range.getNumberOfCharsInWordAfterCursor()); mIC.setSelection(mExpectedSelStart - range.getNumberOfCharsInWordBeforeCursor(), mExpectedSelStart + range.getNumberOfCharsInWordAfterCursor());