Skip to content

Fix edge key popup: use hitbox bounds in squaredDistanceToEdge - #391

Open
AZADAYAZ wants to merge 9 commits into
LeanBitLab:mainfrom
AZADAYAZ:fix/edge-key-popup-squared-distance
Open

Fix edge key popup: use hitbox bounds in squaredDistanceToEdge#391
AZADAYAZ wants to merge 9 commits into
LeanBitLab:mainfrom
AZADAYAZ:fix/edge-key-popup-squared-distance

Conversation

@AZADAYAZ

@AZADAYAZ AZADAYAZ commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Problem

On edge keys (leftmost column: 1, Q, A and rightmost column: 0, Ü, İ), key preview popups do not appear during normal tapping — they only show up when long-pressing. Additionally, when the finger is in the extended hitbox area (near the screen edge), the popup panel cannot correctly detect finger position.

Root Cause

The squaredDistanceToEdge() method in Key.java uses the visual bounds of the key (getX(), mWidth, getY(), mHeight) for distance calculations. However, for edge keys, markAsLeftEdge() and markAsRightEdge() extend the hitbox (mHitBox) beyond the visual bounds. This inconsistency creates the following problem:

  1. isOnKey() correctly uses the extended hitbox → the touch is recognized as being on the key
    1. squaredDistanceToEdge() uses visual bounds → the distance from the visual edge is very large
    1. Result: PointerTracker in isMajorEnoughMoveToBeOnNewKey() interprets the finger as having left the key, canceling the key preview popup
      Since the long-press flow (onLongPressed) does not perform this distance check, long-press popups still work — which is why the issue only manifests during normal tapping.

Fix

Changed squaredDistanceToEdge() to use mHitBox bounds instead of visual bounds:

- final int left = getX();
- - final int right = left + mWidth;
- - final int top = getY();
- - final int bottom = top + mHeight;
- + final int left = mHitBox.left;
- + final int right = mHitBox.right - 1;
- + final int top = mHitBox.top;
- + final int bottom = mHitBox.bottom - 1;
- ```
## Impact Analysis

| Usage | File | Effect |
|-------|------|--------|
| Nearest key selection | `KeyDetector.java` | No change — already filtered by `isOnKey()` hitbox check |
| Finger-off-key detection | `PointerTracker.java` | **Primary fix** — edge keys now correctly recognized |
| Popup key selection | `PopupKeysDetector.java` | **Positive effect** — extended hitbox now used for proximity |

## Backward Compatibility

For interior keys, `mHitBox` equals the visual bounds, so existing behavior is fully preserved. The fix only affects edge keys where the hitbox has been explicitly extended.

AZADAYAZ and others added 9 commits July 17, 2026 04:51
Co-authored-by: LeanBitLab <173956434+LeanBitLab@users.noreply.github.com>
Co-authored-by: LeanBitLab <245915690+LeanBitLab@users.noreply.github.com>
Edge keys (leftmost and rightmost column keys like 1, Q, A and 0, Ü, İ)
have their touch hitbox extended via markAsLeftEdge() and markAsRightEdge()
to respond to touches near the screen edges. However, squaredDistanceToEdge()
was using the visual bounds (getX(), mWidth, getY(), mHeight) instead of
the extended hitbox (mHitBox) for distance calculations.

This caused a mismatch: isOnKey() correctly recognized touches in the
extended hitbox area, but squaredDistanceToEdge() calculated a large distance
from the visual edge, making the pointer tracker think the finger had left
the key. As a result, key preview popups never appeared on edge keys during
normal tapping, and long-press popup panels could not detect finger position
on the extended area.

This change makes squaredDistanceToEdge() use mHitBox bounds consistently,
fixing popup behavior for edge keys while preserving existing behavior for
interior keys where hitbox equals visual bounds.

Fixes: LeanBitLab#292
…squared-distance

# Conflicts:
#	app/src/main/java/helium314/keyboard/latin/RichInputConnection.java
#	app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java
#	app/src/main/res/values-tr/strings.xml
After merge conflict resolution, 32 string entries were duplicated
(pinned_toolbar_keys, quick_pin_toolbar_keys, show_popup_keys_main, etc.).
This caused Resource and asset merger to fail with:
'Found item String/pinned_toolbar_keys more than one time'

Remove the duplicates, keeping the first occurrence of each key.
In Android XML string resources, single quotes must be escaped as \'.
Unescaped single quotes cause 'Invalid unicode escape sequence' errors
during AAPT2 compilation.

This fixes the CI build error for PR LeanBitLab#391.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant