Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-select text with selection keys #973

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ public void hapticAndAudioFeedback(final int code, final int repeatCount) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ public boolean canDeleteCharacters() {
return mExpectedSelStart > 0;
}

public boolean canForwardDeleteCharacters() {
public boolean noTextAfterCursor() {
final CharSequence after = getTextAfterCursor(1, 0);
return !TextUtils.isEmpty(after);
return TextUtils.isEmpty(after);
}

/**
Expand Down Expand Up @@ -728,12 +728,17 @@ public boolean setSelection(final int start, final int end) {

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());
Expand Down