Selection handles: capture base line at grab (fix jitter runaway)
The relative-line mapping resolved the anchor's base line from the anchor's CURRENT byte on every drag event. Once the anchor crossed a line, its own movement fed back into its target: a finger jittering near a line boundary added one more line per event and raced the anchor to the bottom of the file (reported: tiny vertical movements jump the anchor off-screen). Capture the anchor's visual line once at the grab (SelDragPressLine) and compute the target from that fixed base. A jitter test (TestSelDrag_EndHandle_JitterNearLineBoundary_Stable) pins the runaway: mutation-verified against the per-event re-resolution.
This commit is contained in:
+35
-11
@@ -87,12 +87,31 @@ on an idle window and every menu tap was swallowed.
|
||||
|
||||
## 2. Evidence (verified against gioui.org v0.10.0 sources, the live repo's version)
|
||||
|
||||
1. **`widget.Editor` is not virtualized** — it shapes the *entire* document per
|
||||
invalidation and keeps a ~200 B/rune in-memory `glyphIndex`. Measured on this
|
||||
box: 1 MB ≈ 17 ms/keystroke & ~0.32 GB; 3 MB ≈ 1.7 GB; 4 MB OOM-killed the host.
|
||||
Planning figure **~0.5 GB of RAM per 1 MB of text**. A phone cannot edit 10 MB
|
||||
in `widget.Editor`. This is *why* the live repo went the chunked-buffer route,
|
||||
and it's the reason v1's "just use the widget" was wrong for large files.
|
||||
1. **`widget.Editor` is not virtualized** — `textView.layoutText` seeks to the
|
||||
start and shapes the *entire* document on every invalidation (text edit,
|
||||
size/param change), with an infinite viewport; the shaper's `document.reset()`
|
||||
is `lines = lines[:0]`, so the backing array of the largest layout is retained
|
||||
forever. **Re-benchmarked 2026-08-18 against v0.10.0** (plain `text.Shaper`,
|
||||
whole-document shape, the widget's exact call pattern; x86_64 VM):
|
||||
|
||||
| doc | shape time (per edit/keystroke) | retained heap |
|
||||
|---|---|---|
|
||||
| 1 MB | ~120 ms | ~5 MB |
|
||||
| 2 MB | ~0.4 s | ~7 MB |
|
||||
| 5 MB | ~3.4 s | ~15 MB |
|
||||
| 10 MB | ~14 s | ~29 MB |
|
||||
|
||||
The **CPU wall is the decision argument**: a full re-shape on every keystroke
|
||||
is already sluggish at 1 MB (~8 fps of edits) and unusable above ~2 MB; a
|
||||
phone CPU (3–10× slower than this VM) is worse. Memory grows only ~3× the
|
||||
text size with the raw shaper — the earlier "~0.5 GB per MB" figures (which
|
||||
likely included Android PSS overhead / an older version) do not reproduce, but
|
||||
they are not needed: the linear per-edit shape cost alone rules out
|
||||
`widget.Editor` for multi-MB files. This is *why* the live repo went the
|
||||
chunked-buffer route, and it's the reason v1's "just use the widget" was
|
||||
wrong for large files. (For small files — sub-MB notes — `widget.Editor`
|
||||
would be adequate; the custom editor is only strictly required above ~1 MB,
|
||||
but the app's 50 MB target is 50× that.)
|
||||
2. **The Android IME works through the op layer, not the widget.** The
|
||||
`window`'s editor state (`app.Window` → `input.EditorState{Selection, Snippet}`)
|
||||
is what `GioInputConnection` (Android's `InputConnection`) reads. It is fed by
|
||||
@@ -975,13 +994,18 @@ downward, dragging the start handle up extends it upward. The mapping is
|
||||
relative (displacement from the grab, not the finger's absolute line)
|
||||
precisely because the grab is usually a line or more below the anchor:
|
||||
tracking the finger's absolute line would first drag the anchor the wrong
|
||||
way, through a collapse, before it ever reached the anchor's line.
|
||||
Regressions in `touch_selection_test.go`:
|
||||
way, through a collapse, before it ever reached the anchor's line. The
|
||||
base line is captured **once at the grab** and never re-resolved from the
|
||||
anchor's current byte: that would feed the anchor's own movement back
|
||||
into its target line, and a finger jittering near a line boundary would
|
||||
race the anchor off the screen (one extra line per event — reported as
|
||||
"tiny vertical movements jump the anchor to the top/bottom of the
|
||||
screen"). Regressions in `touch_selection_test.go`:
|
||||
`TestSelDrag_StartHandle_PressOnLineBelow_KeepsSelection` (the original
|
||||
bug's geometry), `TestSelDrag_EndHandle_DragDownExtendsAcrossLines`,
|
||||
`TestSelDrag_StartHandle_DragUpExtendsToLineAbove` — all
|
||||
mutation-verified against both the pre-fix mapping and the
|
||||
absolute-finger-line variant.
|
||||
`TestSelDrag_StartHandle_DragUpExtendsToLineAbove`,
|
||||
`TestSelDrag_EndHandle_JitterNearLineBoundary_Stable` (the runaway) — all
|
||||
mutation-verified against the pre-fix variants.
|
||||
|
||||
**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
|
||||
|
||||
Reference in New Issue
Block a user