Repository navigation
fix(tui): give drag-edge autoscroll its own rate; replace wheel momentum with discrete scrolling - #1333
fix(tui): give drag-edge autoscroll its own rate; replace wheel momentum with discrete scrolling#1333zipadoodlez wants to merge 8 commits into
Conversation
…m-style) Mouse-wheel scrolling simulated trackpad physics: a velocity multiplier from the gap between events, a 30-line momentum queue, and an ease-out drain that kept gliding after the gesture. A terminal reports discrete notches, so the "flick force" was a guess, and it was wrong for the one programmatic caller: the drag-to-copy edge autoscroll drives one line per redraw tick, so every tick looked like a hard flick and the view scrolled ~3x too fast, then glided after release. Scroll a wheel notch by a fixed WHEEL_LINES (Neovim's mousescroll ver:3) immediately, and route native-scroll row deltas straight through. Deletes the queue, acceleration multiplier, drain animation, its redraw reason, and the session picker's dead timestamp. The drag edge autoscroll now steps one line per tick on a fixed cadence (REDRAW_COPY_AUTOSCROLL in redraw_schedule), reusing the wheel's per-line primitive (apply_mouse_scroll_step) and never touching the wheel path.
help, changelog, and model status each carried their own copy of the same key-handling match, mouse-step arm, and render clamp/percent block. Share one implementation for each: - overlay_scroll_key(&mut Option<usize>, code): the shared Esc/q, j/k, PageUp/PageDown, g/G match, with extras (model status 'c') layered after. - overlay_scroll_step(&mut Option<usize>, direction): the mouse-wheel step. - overlay_scroll_info(total, visible, scroll) -> (scroll, " NN% "): the render clamp plus the title percentage. No new type: Option<usize> (None = closed, usize::MAX = bottom) already is the model. Chat, side/diff, and the picker preview are deliberately untouched.
A deliberate wheel notch still moves WHEEL_LINES (3), but rapid notches now ramp toward WHEEL_LINES_MAX (10), using the only velocity signal a terminal gives: the gap since the previous notch. Each notch lands immediately. This is the velocity scaling without the old queue/glide, which is what the drag-edge autoscroll abused. Kept separate on purpose: autoscroll uses the per-line step, never enqueue_mouse_scroll, so a programmatic scroll cannot be mistaken for a flick. Adds a unit test for wheel_lines_for_gap; the drag/render paths are unchanged.
The hot-zone depth now sets how many lines the autoscroll moves per tick: on the boundary row 3, deeper in the band 2, at the inner edge 1. Dragging just inside the edge is therefore slow and controllable, and dragging right onto it is fast, matching the browser feel. Widen the autoscroll state to carry the speed and slow the tick to 60ms so the slow tier is ~17 lines/s. copy_pane_vertical_edge_point returns the proximity speed with the edge point; the drag arm refreshes it on re-arm without an extra nudge.
progress_copy_selection_edge_autoscroll re-implemented the "scroll N lines, stopping at the edge" loop that scroll_target_lines already is. Pass the proximity speed straight through instead. Tighten visibility to match callers (scroll_target_lines pub(super), apply_mouse_scroll_step private again).
… ladder - enqueue_mouse_scroll -> scroll_wheel, enqueue_native_scroll -> scroll_rows: neither has queued anything since the momentum removal, so the names lied. - Move WHEEL_LINES to `crate::tui::WHEEL_LINES` and use it in the standalone session picker instead of a second literal `3` with a comment claiming they match. - Mark the velocity ladder with a `ponytail:` note recording that it is jcode's own (Neovim has one fixed `mousescroll`), not a copied standard.
- overlay_scroll_info dedup dropped the `total_lines` binding that draw_changelog_overlay still used for its visible-range clamp. - Duration::as_millis takes &self, so Option<Duration>::map could not take the method item directly; use a closure. `cargo check -p jcode-tui` is clean.
…base tier Adds a regression test for the reported bug: one autoscroll tick moves the small proximity tier (1-3 lines, never a velocity-scaled wheel notch), held ticks do not accelerate, a row deeper in the hot zone is never faster, and the view does not drift after release (the old momentum glide). The two overlay wheel tests issue notches back to back, which the new velocity ladder reads as a flick (9 lines instead of the base 3). Clear `last_wheel` between notches so they measure the base tier deterministically. `cargo test -p jcode-tui --lib`: 2302 passed before this change, with the two overlay tests failing; both now pass.
|
| if state.copy_selection_edge_autoscroll_active() { | ||
| return REDRAW_COPY_AUTOSCROLL; |
There was a problem hiding this comment.
When a drag selection remains at a pane edge while output is streaming, this branch returns the fixed 60 ms autoscroll interval before the live-output branches can select the normal 16 ms cadence at 60 fps. Transcript updates and live animations are therefore less responsive for the duration of the drag. This is non-blocking, but autoscroll movement should be paced at 60 ms without replacing a concurrently faster redraw cadence.
Artifacts
- Temporary script injects and runs a focused Rust test, then restores the test sources with an exit trap; it directly verifies the scheduling branch.
- Captured output from the executed focused test records the normal 60fps live-output interval as 16ms, establishing the comparison baseline.
- Captured successful test output shows one passing test, with live output plus active copy edge autoscroll returning 60ms; the claim is confirmed.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/redraw_schedule.rs
Line: 431-432
Comment:
**Preserve live redraw cadence**
When a drag selection remains at a pane edge while output is streaming, this branch returns the fixed 60 ms autoscroll interval before the live-output branches can select the normal 16 ms cadence at 60 fps. Transcript updates and live animations are therefore less responsive for the duration of the drag. This is non-blocking, but autoscroll movement should be paced at 60 ms without replacing a concurrently faster redraw cadence.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Closes #1332
Two separate scroll paths
This PR touches two mechanisms that are easy to conflate. Naming them once so the
rest reads cleanly:
delivers discrete notch events. This is the path that had momentum
(
enqueue_mouse_scroll, a velocity multiplier, a queue, a frame drain).by itself, one step per redraw tick, while the cursor sits at the top or bottom
edge of a pane (
progress_copy_selection_edge_autoscroll). No wheel is involved,and no mode is required: the default drag-to-copy reaches this path, and
Alt+yonly pins copy mode on explicitly.
The reported bug is entirely in the second mechanism. Its cause is that it
borrowed the first mechanism's model.
The bug (drag-edge autoscroll)
While drag-selecting the transcript — the default browser-style drag-to-copy, no
mode needed, and also explicit copy mode (
Alt+y) — holding the cursor at the topor bottom edge of the chat pane scrolls ~3 lines per frame (~180 lines/s at 60fps)
and keeps drifting after the mouse button is released. The intent was a
browser-like continuous scroll of roughly one line per tick that stops on release.
Root cause (drag-edge autoscroll used the wheel model)
progress_copy_selection_edge_autoscroll(app/copy_selection.rs) calledscroll_copy_selection_pane->enqueue_mouse_scroll(app/navigation.rs), thewheel path. That path infers "how hard the wheel was flicked" from the gap
between wheel events and then queues an intent to drain over frames.
An autoscroll tick fires every ~16ms at 60fps, so the gap looked like a hard
flick (2x): each tick queued
min(3 * 2, 5) = 5lines against a 30-line cap,while each call drained up to 3 lines and
mouse_scroll_drain_amountdrained 3more per frame. The queue saturated at 30 and drained a flat 3 lines/frame. After
release, the leftover queue kept draining for ~10 frames, which is the drift.
So: a programmatic, tick-driven scroll was being expressed through a model of
human flick physics. A terminal reports discrete notches, not force, so that
model's input was never real; it just happened to be harmless for actual wheel
input and actively wrong for this caller.
Why this is more than one change
CONTRIBUTING asks for focused changes and to split large work. This is one
coherent change with two separable riders; I am happy to split any of it.
Core (not separable). The bug exists because the autoscroll shares the wheel
path. Two ways to fix it:
Smaller diff, but it leaves the trap: the next programmatic scroll that reaches
for the shared entry point reproduces the bug, and the queue's constants stay
load-bearing for a caller they were never designed for.
I chose (2), so the core is "fix the autoscroll" plus "delete the mechanism it was
misusing". Those are one decision, which is why the core is larger than a clamp.
Rider 1 (separable, feel). Removing the wheel momentum model also removed the
only thing that made a fast flick cover more ground. With no flick model at all,
WHEEL_LINESwould be a flat 3. This rider restores "deliberate notch staysprecise, flick covers ground" as a discrete notch-size ladder, and gives the
autoscroll a proximity ladder for the same reason. Pure taste; drop it and keep a
flat
WHEEL_LINESif you prefer.Rider 2 (fully separable, no behavior change). help / changelog / model-status
each carried their own copy of the same key match, mouse step, and render clamp.
I deduped them because I was already reasoning about those three offsets. Splitable
into its own PR with no effect on the rest.
Commit map for a subset:
e2aa58b1a,71420106b,ba522af28,d091dc40cd6c22a4a3,ea741191a2239560a31407449d9The change
Drag-edge autoscroll (the fix)
entry point. A programmatic scroll can no longer be mistaken for a flick.
REDRAW_COPY_AUTOSCROLL, 60ms) instead ofinheriting
redraw_fps, so speed is a property of the gesture, not the display.(
zone - depthclamped to 1..=3).Mouse-wheel scrolling (model replacement)
scroll_wheelmovesWHEEL_LINES(3, matching Neovim'smousescroll ver:3)immediately, and
scroll_rowsapplies a native host's exact row delta.ease-out frame drain, the
mouse_scroll_animationredraw reason,has_pending_mouse_scroll_animation(trait method plus eight schedule callsites), and the session picker's dead write-only timestamp.
6 at <=40ms, 9 at <=15ms, capped at 10.
picker preview), same routing.
Overlays (rider 2, no behavior change)
One
overlay_scroll_key, oneoverlay_scroll_step, oneoverlay_scroll_inforeplace three copies each.
Option<usize>(None= closed,usize::MAX= bottom)was already the model, so no new type.
Net: 20 files, +361/-527.
Behavior changes, per mechanism
Drag-edge autoscroll
Mouse-wheel scrolling
flick.
the new ladder is visible. It is why two overlay tests had to clear their
inter-notch timestamp to measure the base tier.
Native scrollbar (host-provided deltas)
Tradeoffs and edge cases
slow notch drained fully inside the same call), so the perceived loss is small,
but it is a deliberate removal.
with a
ponytail:note and tunable in one place (wheel_lines_for_gap,WHEEL_LINES_MAX).active, including during streaming. Fine for a transient gesture; flagging it.
is jcode's existing behavior. Neovim instead scrolls per drag event, by the
distance the cursor is past the edge; we did not adopt that.
overscroll.
Verification
cargo check -p jcode-tuiclean.cargo check -p jcode-tui --all-targetsclean.cargo test -p jcode-tui --lib: 2302 passed.test_edge_autoscroll_rate_is_proximity_scaled_and_stops_on_releaseasserts theautoscroll rate, that held ticks do not accelerate, that the proximity tier never
gets faster deeper in the zone, and that nothing drifts after release.
hold the cursor at the bottom edge, both in default mode and after
Alt+y. Slownear the inner edge, faster on the boundary, stops on release.
render, remote reload). They are pre-existing and unrelated: several pass in
isolation (flaky under parallel execution), one fails deterministically in
commands_accounts_02, and none are in files this PR touches.Review notes
drain deceleration, queue saturation). The behavior they asserted does not exist
anymore.
enqueue_native_scrollnow applies its exact rowdelta immediately, so
state_model_poke_02asserts immediate deltas rather thanqueued rows.