Skip to content

Commit

Permalink
select keys can now de-select text
Browse files Browse the repository at this point in the history
  • Loading branch information
devycarol committed Jul 12, 2024
1 parent d7d4767 commit ad49142
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit ad49142

Please sign in to comment.