Redesign selection handles (teardrop + 48dp grab); place menu above selection
- Handles are now teardrops (stem + filled circle) like the native Android selector: 20dp circle normally, 28dp while dragging. - The grab region is a 48dp box around the circle centre, independent of the visual size; the old 16dp target was not grabbable by finger. - The copy/cut/paste menu is placed ABOVE the selected line (native behaviour), flipping below only when there is no room above. The menu is drawn last (top of the z-order) and Gio routes a touch to the topmost op whose clip contains it, so a below-placed menu covered the handles' grab boxes and silently stole every handle-drag press. - Regressions: menu above-placement arithmetic, first-line flip-below, and the existing tracking/clamp tests updated for the new policy. - On-device verified: handle drags work with the menu up (previously dead lower grab region), first-line handles still grabbable from the uncovered top strip, menu taps and tap-to-clear unchanged. - doc/development_plan.md section 15 records the z-order/placement contract.
This commit is contained in:
@@ -69,11 +69,11 @@ func TestSelectionMenu_FollowsTextAcrossScroll(t *testing.T) {
|
||||
t.Fatal("menu not shown for a visible selection")
|
||||
}
|
||||
y0 := e.MenuRect.Y
|
||||
// The menu sits below the anchor's line: lineTop(line 5) = reg.Y + 5*lh
|
||||
// The menu sits ABOVE the anchor's line: lineTop(line 5) = reg.Y + 5*lh
|
||||
// (reg.Y = 10+52, the anchor's visual line index is 5).
|
||||
wantY0 := ui.Dp(62) + ui.Dp(5*lh) + EffectiveLineHeight() + 8
|
||||
wantY0 := ui.Dp(62) + ui.Dp(5*lh) - menuH - 8
|
||||
if !dpeq(y0, wantY0) {
|
||||
t.Fatalf("initial menu Y = %v, want %v (below the anchor line)", y0, wantY0)
|
||||
t.Fatalf("initial menu Y = %v, want %v (above the anchor line)", y0, wantY0)
|
||||
}
|
||||
|
||||
// Scroll down by exactly 2 lines and lay out again.
|
||||
@@ -117,3 +117,43 @@ func TestSelectionMenu_ClampsWhenTextLeavesView(t *testing.T) {
|
||||
t.Fatalf("menu Y = %v, want 8 (pinned to the window top when the text is above the viewport)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSelectionMenu_FlipsBelowOnFirstLine checks the edge where there is no
|
||||
// room above the anchor (selection on the first line): the menu must flip
|
||||
// below the line rather than clamping to the window top and sitting over the
|
||||
// anchor's own text.
|
||||
func TestSelectionMenu_FlipsBelowOnFirstLine(t *testing.T) {
|
||||
lh := menuTrackState(t)
|
||||
|
||||
TheState.Editor.Buffer = "aa\nbb\n"
|
||||
SetSelection(0, 2) // "aa" on line 0
|
||||
|
||||
gl := ui.GlyphLayout{LineHeight: EffectiveLineHeight()}
|
||||
const ascent float64 = 14
|
||||
lines := 2
|
||||
for i := 0; i < lines; i++ {
|
||||
for c := 0; c < 2; c++ {
|
||||
gl.ByteOffsets = append(gl.ByteOffsets, i*3+c)
|
||||
gl.X = append(gl.X, ui.Dp(10+10*c))
|
||||
gl.Y = append(gl.Y, ui.Dp(ascent+float64(i)*lh))
|
||||
gl.Advance = append(gl.Advance, 10)
|
||||
}
|
||||
}
|
||||
TheState.Editor.GlyphLayout = gl
|
||||
TheState.LastLineY = ui.Dp(float64(lines) * lh)
|
||||
TheState.Editor.IMEWindowStartByte = 0
|
||||
TheState.ScrollOffset = 0
|
||||
|
||||
EditorLayout(ui.Dp(1000), ui.Dp(2000), false)
|
||||
showSelectionMenu()
|
||||
e := &TheState.Editor
|
||||
if !e.MenuVisible {
|
||||
t.Fatal("menu not shown")
|
||||
}
|
||||
// Line 0 top = reg.Y = 62; above would be 62-52-8 = 2 < 8, so the menu
|
||||
// flips below: 62 + lh + 8.
|
||||
wantY := ui.Dp(62) + EffectiveLineHeight() + 8
|
||||
if !dpeq(e.MenuRect.Y, wantY) {
|
||||
t.Fatalf("menu Y = %v, want %v (flipped below the first line)", e.MenuRect.Y, wantY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,8 +763,12 @@ func hideSelectionMenu() {
|
||||
e.MenuRect = ui.Region{}
|
||||
}
|
||||
|
||||
// positionSelectionMenu places the copy/cut/paste menu below the visual line
|
||||
// containing the anchor (selection end or caret), clamped to the window. It
|
||||
// positionSelectionMenu places the copy/cut/paste menu above the visual line
|
||||
// containing the anchor (selection end or caret) — like the native Android
|
||||
// selection toolbar — falling back to below when there is no room above.
|
||||
// Above matters: the selection handles hang off the line's bottom edge and
|
||||
// their 48dp grab boxes would sit under a below-placed menu; the menu is
|
||||
// drawn last (top of the z-order) and would steal those touches. It
|
||||
// is called from showSelectionMenu and from EditorLayout on every frame
|
||||
// while the menu is visible, so the menu tracks the selected text when the
|
||||
// user scrolls: the menu is anchored to the TEXT (an absolute buffer offset
|
||||
@@ -797,9 +801,18 @@ func positionSelectionMenu(e *EditorState) bool {
|
||||
if winW > 0 && mx+float64(menuW) > winW-8 {
|
||||
mx = winW - float64(menuW) - 8
|
||||
}
|
||||
my := lineTop + float64(EffectiveLineHeight()) + 8 // below the line
|
||||
if winH > 0 && my+float64(menuH) > winH-8 {
|
||||
my = lineTop - float64(menuH) - 8 // flip above the line
|
||||
// Prefer ABOVE the line, like the native Android selection toolbar.
|
||||
// Placing it below would sit over the selection handles' grab region
|
||||
// (the handles hang off the line's bottom edge), and the menu is drawn
|
||||
// last (top of the z-order) so it would steal the touches meant for the
|
||||
// handles. Above keeps the handles fully grabbable. Flip below only when
|
||||
// there is no room above.
|
||||
my := lineTop - float64(menuH) - 8
|
||||
if my < 8 {
|
||||
my = lineTop + float64(EffectiveLineHeight()) + 8 // flip below the line
|
||||
if winH > 0 && my+float64(menuH) > winH-8 {
|
||||
my = winH - float64(menuH) - 8 // clamp to window bottom
|
||||
}
|
||||
}
|
||||
if my < 8 {
|
||||
my = 8
|
||||
@@ -808,9 +821,9 @@ func positionSelectionMenu(e *EditorState) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// showSelectionMenu recomputes the menu items and positions the menu below
|
||||
// the line containing the selection end (or caret). Copy and Cut are
|
||||
// offered only while a selection is active; Paste always.
|
||||
// showSelectionMenu recomputes the menu items and positions the menu above
|
||||
// the line containing the selection end (or caret), falling back to below.
|
||||
// Copy and Cut are offered only while a selection is active; Paste always.
|
||||
func showSelectionMenu() {
|
||||
e := &TheState.Editor
|
||||
if e.TooLarge || len(e.GlyphLayout.ByteOffsets) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user