From a92d108444375a65da957c5c767786b5fa8e2b37 Mon Sep 17 00:00:00 2001 From: Devy Ballard <69347329+devycarol@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:30:29 -0600 Subject: [PATCH] make arrow keys repeatable (#932) only applies to keyboard keys, not in toolbar --- .../main/java/helium314/keyboard/keyboard/Key.java | 12 ++++++++---- .../java/helium314/keyboard/latin/LatinIME.java | 13 ++++++++++--- .../keyboard/latin/RichInputConnection.java | 5 +++++ layouts.md | 1 + 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index 9353546c..2d7896ed 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -1171,13 +1171,17 @@ public class Key implements Comparable { if (mCode <= Constants.CODE_SPACE && mCode != KeyCode.MULTIPLE_CODE_POINTS && mIconName == null) actionFlags |= ACTION_FLAGS_NO_KEY_PREVIEW; switch (mCode) { - case KeyCode.DELETE, KeyCode.SHIFT, Constants.CODE_ENTER, KeyCode.SHIFT_ENTER, KeyCode.ALPHA, Constants.CODE_SPACE, KeyCode.NUMPAD, - KeyCode.SYMBOL, KeyCode.SYMBOL_ALPHA, KeyCode.LANGUAGE_SWITCH, KeyCode.EMOJI, KeyCode.CLIPBOARD -> actionFlags |= ACTION_FLAGS_NO_KEY_PREVIEW; // no preview even if icon! + case KeyCode.DELETE, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT, KeyCode.ARROW_UP, KeyCode.ARROW_DOWN: + // repeating is disabled if a key is configured with pop-ups + if (mPopupKeys == null) + actionFlags |= ACTION_FLAGS_IS_REPEATABLE; + // fallthrough + case KeyCode.SHIFT, Constants.CODE_ENTER, KeyCode.SHIFT_ENTER, KeyCode.ALPHA, Constants.CODE_SPACE, KeyCode.NUMPAD, + KeyCode.SYMBOL, KeyCode.SYMBOL_ALPHA, KeyCode.LANGUAGE_SWITCH, KeyCode.EMOJI, KeyCode.CLIPBOARD: + actionFlags |= ACTION_FLAGS_NO_KEY_PREVIEW; // no preview even if icon! } if (mCode == KeyCode.SETTINGS || mCode == KeyCode.LANGUAGE_SWITCH) actionFlags |= ACTION_FLAGS_ALT_CODE_WHILE_TYPING; - if (mCode == KeyCode.DELETE) - actionFlags |= ACTION_FLAGS_IS_REPEATABLE; mActionFlags = actionFlags; final int altCodeInAttr; // settings and language switch keys have alt code space, all others nothing diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index 72b4fbfd..898c4a23 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -1731,9 +1731,16 @@ public class LatinIME extends InputMethodService implements return; } if (repeatCount > 0) { - if (code == KeyCode.DELETE && !mInputLogic.mConnection.canDeleteCharacters()) { - // No need to feedback when repeat delete key will have no effect. - return; + // No need to feedback when repeat delete/cursor keys will have no effect. + switch (code) { + case KeyCode.DELETE, KeyCode.ARROW_LEFT, KeyCode.ARROW_UP: + if (!mInputLogic.mConnection.canDeleteCharacters()) + return; + break; + case KeyCode.ARROW_RIGHT, KeyCode.ARROW_DOWN: + if (!mInputLogic.mConnection.canForwardDeleteCharacters()) + return; + break; } // TODO: Use event time that the last feedback has been generated instead of relying on // a repeat count to thin out feedback. diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java index 1bbd40a5..a5c96343 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java +++ b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java @@ -363,6 +363,11 @@ public final class RichInputConnection implements PrivateCommandPerformer { return mExpectedSelStart > 0; } + public boolean canForwardDeleteCharacters() { + final CharSequence after = getTextAfterCursor(1, 0); + return !TextUtils.isEmpty(after); + } + /** * Gets the caps modes we should be in after this specific string. *

diff --git a/layouts.md b/layouts.md index 8aa78ebc..e6576eb4 100644 --- a/layouts.md +++ b/layouts.md @@ -62,6 +62,7 @@ If the layout has exactly 2 keys in the bottom row, these keys will replace comm * `popup`: list of keys to add in the popup, e.g. `"label": ")", "popup": {"relevant": [{ "label": "." }]}` is a `)` key with a `.` popup * Note that in popup keys, properties are ignored with the exception of `$`, `code`, `codePoints`, and `label` * When specifying a _selector_ key class in a popup key, it will be evaluated correctly (e.g. for changing popups dependent on shift state) + * If popups are added to repeating keys (e.g. delete, arrow keys), repetition will be disabled. * `width`: width of the key in units of screen width, e.g. a key with `"width": 0.1` has a width of 10% of the screen, defaults to `0` * A special value is `-1`, which means the key expands to the available space not already used by other keys (e.g. the space bar) * `0` is interpreted as follows