Skip to content

Commit 3655957

Browse files
authored
fix(modes): click where a held-key glide left the cursor, not on the grid selection (#1627)
1 parent 89b6f1c commit 3655957

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

internal/app/modes/key_dispatch.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,13 @@ func (h *handlerState) startMotion(key string, actions []string) bool {
479479
return false
480480
}
481481

482+
// The discrete step would have gone through the IPC handler, which drops
483+
// the mode's selection so a later click lands where the cursor went. The
484+
// glide never gets there, so the selection is dropped here.
485+
if tracker, ok := activeModeExtension[selectionTracker](h); ok {
486+
tracker.ClearSelectionPoint()
487+
}
488+
482489
h.motion.Press(motionKeyOf(key), dir, step)
483490

484491
return true

internal/app/simulation_journey_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,62 @@ func TestSimulation_HeldMotionDiagonal(t *testing.T) {
14141414
sim.waitMode(domain.ModeIdle)
14151415
}
14161416

1417+
// TestSimulation_HeldMotionDropsTheGridSelection pins that a held-key glide
1418+
// leaves the click where the cursor went, not on the region the grid had
1419+
// selected: select a region, glide away from it, click.
1420+
func TestSimulation_HeldMotionDropsTheGridSelection(t *testing.T) {
1421+
cfg := simConfig()
1422+
cfg.HeldRepeat.Enabled = true
1423+
1424+
sim := newSimHarness(t, cfg, nil)
1425+
1426+
sim.pressHotkey(recursiveGridHotkey)
1427+
sim.waitMode(domain.ModeRecursiveGrid)
1428+
1429+
sim.waitFor("recursive grid drawn", func() bool {
1430+
_, ok := sim.overlay.lastRecursiveGridBounds()
1431+
1432+
return ok
1433+
})
1434+
1435+
movesBefore := sim.cursor.moveCount()
1436+
1437+
// "r" selects the top-left cell, which moves the cursor onto its center.
1438+
sim.press("r")
1439+
1440+
sim.waitFor("cursor moved onto the selected region", func() bool {
1441+
return sim.cursor.moveCount() > movesBefore
1442+
})
1443+
1444+
selected := sim.cursor.position()
1445+
1446+
sim.press("Right")
1447+
1448+
sim.waitFor("cursor glided right", func() bool {
1449+
return sim.cursor.position().X > selected.X
1450+
})
1451+
1452+
sim.press("__keyup_Right")
1453+
1454+
sim.press("Shift+L") // left_click
1455+
1456+
sim.waitFor("click recorded", func() bool {
1457+
return len(sim.ax.recordedClicks()) >= 1
1458+
})
1459+
1460+
got := sim.ax.recordedClicks()[0]
1461+
if got.action != action.TypeLeftClick {
1462+
t.Fatalf("expected a left click, got %+v", got)
1463+
}
1464+
1465+
if got.point.Y != selected.Y || got.point.X <= selected.X {
1466+
t.Fatalf("click at %v, expected to the right of the grid selection %v", got.point, selected)
1467+
}
1468+
1469+
sim.press("Escape")
1470+
sim.waitMode(domain.ModeIdle)
1471+
}
1472+
14171473
// TestSimulation_DragJourney covers the drag primitives: mouse down at the
14181474
// cursor, arrow-key relative movement while holding, mouse up at the new
14191475
// position.

0 commit comments

Comments
 (0)