Fix selection-handle drags, menu anchoring, and left-edge back-gesture theft
Three user-reported selection bugs, one root cause each:
1. Start handle ungrabbable at line start. Two interacting causes:
a) The 48dp grab box straddles two visual lines; a finger in the
lower half mapped (by y-to-line) to the neighbouring line, whose
byte past the other handle clamped to a zero-length selection ->
cleared on the first drag event. The cleared selection
un-registered the drag op, so the router silently stopped
delivering drag events (the observed 'stream cutoff'). Fix:
handle drags now project the finger's x onto the anchor's own
visual line (visualLineOfByte + textPosOnLineAtX); the anchor
never crosses lines during a handle drag.
b) A horizontal flick from the line-start handle (screen x~26px)
started the system back gesture, which cancelled the touch
stream. Fix: report the handle grab rects as system gesture
exclusion rects (setSystemGestureExclusionRects, API 29+),
marshalled to the UI thread via a PadExcl smali Runnable
(generated identically by build_emu.sh/build_phone.sh).
2. End-handle drag downward made the menu chase the finger and cover
the selection. Fix: the menu anchors to the STABLE end of the
selection (the end not being dragged), so it stays parked by the
selection start, clear of the finger and the highlighted text.
3. Menu above the selection vanished permanently when the selection
was extended onto the top line. Fix: off-window anchors no longer
hide the menu while any part of the selection is visible (keep-last
rect, clamped); hiding happens only for fully off-window selections.
Also: registerDrag simplified (single shared drag path, body before
handles in z-order), debug logging removed, regression tests
(mutation-verified) for line projection and menu anchoring, docs
section 17. Verified on device: start-handle drag shrinks the word
without clearing or triggering back navigation; end-handle vertical
drag leaves menu/highlight/handles undisturbed; menu stays visible
with the selection at the top line.
This commit is contained in:
@@ -946,3 +946,71 @@ shorter bar, selections on the first lines flip below because there is
|
||||
no room above, and the menu may overlap the top bar when clamped high —
|
||||
both are the native toolbar's behaviour (transient, dismissed by
|
||||
tapping elsewhere).
|
||||
|
||||
## 17. Handle drags, menu anchoring, and the left-edge gesture (2026-08-18)
|
||||
|
||||
**Line projection for handle drags.** A selection handle's 48dp grab box
|
||||
(straddling two visual lines, because the teardrop hangs off the line's
|
||||
bottom edge) is larger than the line it belongs to. A finger in the lower
|
||||
half of the box maps, by pure y-to-line, to the NEIGHBOURING line.
|
||||
Mapping the finger to its own line was fatal for a start-handle drag: the
|
||||
neighbouring-line byte is usually past the other handle, the clamp
|
||||
collapses the selection to zero length, the selection is cleared — and a
|
||||
cleared selection un-registers the drag op, so Gio's router silently
|
||||
stops delivering drag events to it (an inactive handler is deleted at the
|
||||
next frame boundary without a cancel). Every downstream symptom — the
|
||||
"stream cutoff", a tap landing on release, the system back gesture
|
||||
firing on subsequent edge swipes — was a consequence of that single
|
||||
collapse, not a system-side touch filter.
|
||||
|
||||
Contract: a handle drag projects the finger's X onto the ANCHOR's own
|
||||
visual line (the line the handle belongs to, resolved the same way the
|
||||
renderer resolves the handle position). The anchor therefore never
|
||||
crosses a line during a handle drag; vertical finger movement is ignored.
|
||||
The trade-off vs. native (native can walk the anchor to another line by
|
||||
dragging across lines) is accepted: the reported bug was worse than the
|
||||
sacrifice, and body drags still move whole selections across lines.
|
||||
Regression: `TestSelDrag_*_PressOnLineBelow_*` in
|
||||
`touch_selection_test.go` (both mutation-verified against the pre-fix
|
||||
mapping).
|
||||
|
||||
**Menu anchors to the stable end.** While a start-handle drag is in
|
||||
progress the selection start is the moving end, so the menu anchors to
|
||||
the selection END (and vice-versa the default anchor is the start). The
|
||||
menu therefore never chases the finger: dragging the end handle away
|
||||
leaves the menu parked by the selection start, clear of the finger's
|
||||
path and (combined with the above/below contract of section 15) clear of
|
||||
the selected text. Verified on device: a long vertical end-handle drag
|
||||
with the menu up leaves the menu, the highlight and both handles
|
||||
undisturbed.
|
||||
|
||||
**The menu is never sticky-hidden while any part of the selection is
|
||||
visible.** If both selection ends fall outside the shaped window (e.g.
|
||||
the viewport scrolled away) but the selection still intersects the
|
||||
window, the menu keeps its previous position, clamped inside the window;
|
||||
it is hidden only when the whole selection is off-window, and re-anchoring
|
||||
(the next selection change) re-shows it. This replaces the earlier
|
||||
behaviour where an off-window anchor coordinate hid the menu
|
||||
permanently. Regression:
|
||||
`TestSelectionMenu_KeptVisibleWhileSelectionPartiallyOffScreen`.
|
||||
|
||||
**Left-edge exclusion for the start handle.** On gesture navigation
|
||||
(API 30+/35) a horizontal rightward swipe starting within ~23dp of the
|
||||
left screen edge starts the system BACK gesture; the gesture previews,
|
||||
cancels the in-app touch stream (ACTION_CANCEL), hides the IME and
|
||||
navigates. A start handle at the beginning of a line sits at screen
|
||||
x≈26px — inside that zone — so grabbing it with a horizontal flick
|
||||
navigated away instead of dragging. The app cannot disable the system
|
||||
back gesture, but Android lets a view opt specific rects out via
|
||||
`View.setSystemGestureExclusionRects` (API 29+). The editor reports the
|
||||
two selection-handle grab rects (screen px) every frame; the app
|
||||
forwards them to the view. Two invariants: the call must run on the
|
||||
Android UI thread (the Go frame loop is not it — it is marshalled via a
|
||||
tiny `PadExcl` Runnable posted through `View.post`, generated by the
|
||||
build scripts' smali patch, which must stay byte-identical between
|
||||
`build_emu.sh` and `build_phone.sh`), and the rects are in the view's
|
||||
coordinate system (== window-local px for the full-screen GioView).
|
||||
Verified on device: with the exclusion active, horizontal drags from the
|
||||
left-edge start handle no longer trigger `startBackNavigation`
|
||||
(`dumpsys window` shows the exclusion region; logcat shows zero
|
||||
back-gesture previews).
|
||||
|
||||
Reference in New Issue
Block a user