Skip to content

fix(tui): give drag-edge autoscroll its own rate; replace wheel momentum with discrete scrolling - #1333

Closed
zipadoodlez wants to merge 8 commits into
1jehuang:masterfrom
zipadoodlez:fix/copy-drag-autoscroll-speed
Closed

zipadoodlez wants to merge 8 commits into
1jehuang:masterfrom
zipadoodlez:fix/copy-drag-autoscroll-speed

Conversation

@zipadoodlez

Copy link
Copy Markdown
Contributor

Closes #1332

Two separate scroll paths

This PR touches two mechanisms that are easy to conflate. Naming them once so the
rest reads cleanly:

  • Mouse-wheel scrolling — the user turns a wheel or trackpad. The terminal
    delivers discrete notch events. This is the path that had momentum
    (enqueue_mouse_scroll, a velocity multiplier, a queue, a frame drain).
  • Drag-edge autoscroll — while drag-selecting the transcript, jcode scrolls
    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+y
    only 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 top
or 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) called
scroll_copy_selection_pane -> enqueue_mouse_scroll (app/navigation.rs), the
wheel 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) = 5 lines against a 30-line cap,
while each call drained up to 3 lines and mouse_scroll_drain_amount drained 3
more 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:

  1. Carve the autoscroll out of that path, keep the momentum model for the wheel.
    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.
  2. Remove the momentum model, make a wheel notch a discrete command.

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_LINES would be a flat 3. This rider restores "deliberate notch stays
precise, 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_LINES if 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:

  • core: e2aa58b1a, 71420106b, ba522af28, d091dc40c
  • rider 1: d6c22a4a3, ea741191a
  • rider 2: 2239560a3
  • cleanup: 1407449d9

The change

Drag-edge autoscroll (the fix)

  • Steps lines through the plain per-line primitive, and never calls the wheel
    entry point. A programmatic scroll can no longer be mistaken for a flick.
  • Rate comes from a fixed tick cadence (REDRAW_COPY_AUTOSCROLL, 60ms) instead of
    inheriting redraw_fps, so speed is a property of the gesture, not the display.
  • With rider 1: 1-3 lines per tick, scaled by distance into the edge hot zone
    (zone - depth clamped to 1..=3).

Mouse-wheel scrolling (model replacement)

  • scroll_wheel moves WHEEL_LINES (3, matching Neovim's mousescroll ver:3)
    immediately, and scroll_rows applies a native host's exact row delta.
  • Deleted: the momentum queue and its fields, the velocity multiplier, the
    ease-out frame drain, the mouse_scroll_animation redraw reason,
    has_pending_mouse_scroll_animation (trait method plus eight schedule call
    sites), and the session picker's dead write-only timestamp.
  • With rider 1: wheel lines scale with the gap between notches — 3 deliberate,
    6 at <=40ms, 9 at <=15ms, capped at 10.
  • Wheel input is otherwise unchanged: same targets (chat, side pane, overlays,
    picker preview), same routing.

Overlays (rider 2, no behavior change)

One overlay_scroll_key, one overlay_scroll_step, one overlay_scroll_info
replace 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

  • 1-3 lines per 60ms tick by proximity, ~17-50 lines/s, independent of fps.
  • Stops immediately on release. No drift.

Mouse-wheel scrolling

  • A notch is now a fixed number of lines instead of a queue: 3, up to 10 on a fast
    flick.
  • No momentum glide.
  • Two rapid notches count as a flick (up to 9 lines). Intended, and the one place
    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)

  • The full delta applies immediately, with no animated remainder.

Tradeoffs and edge cases

  • Wheel momentum glide is gone. It only triggered on very fast flicks before (a
    slow notch drained fully inside the same call), so the perceived loss is small,
    but it is a deliberate removal.
  • The wheel notch ladder is jcode's own heuristic, not copied from Neovim. Marked
    with a ponytail: note and tunable in one place (wheel_lines_for_gap,
    WHEEL_LINES_MAX).
  • The autoscroll cadence pins the redraw loop to 60ms while a drag autoscroll is
    active, including during streaming. Fine for a transient gesture; flagging it.
  • Autoscroll still keeps scrolling while the cursor is held perfectly still. That
    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.
  • Untouched: keyboard chat scrolling, side-pane scrolling, tail catch-up, elastic
    overscroll.

Verification

  • cargo check -p jcode-tui clean.
  • cargo check -p jcode-tui --all-targets clean.
  • cargo test -p jcode-tui --lib: 2302 passed.
    test_edge_autoscroll_rate_is_proximity_scaled_and_stops_on_release asserts the
    autoscroll rate, that held ticks do not accelerate, that the proximity tier never
    gets faster deeper in the zone, and that nothing drifts after release.
  • Manual, Linux/x86_64, foot 1.28.0, Wayland: drag-select in the transcript and
    hold the cursor at the bottom edge, both in default mode and after Alt+y. Slow
    near the inner edge, faster on the boundary, stops on release.
  • 18 tests fail in the full suite on this machine (accounts, onboarding, golden
    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

  • Removed tests only covered the deleted wheel queue (acceleration multiplier,
    drain deceleration, queue saturation). The behavior they asserted does not exist
    anymore.
  • One native-scroll test changed: enqueue_native_scroll now applies its exact row
    delta immediately, so state_model_poke_02 asserts immediate deltas rather than
    queued rows.

…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.
@greptile-apps

greptile-apps Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

Safe to merge with a non-blocking responsiveness concern: live output becomes less smooth while copy-edge autoscroll is active.

Findings

  1. P2 Preserve live redraw cadence ▶
Fix with agent prompt
### Issue 1
crates/jcode-tui/src/tui/redraw_schedule.rs:431-432
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • The redraw scheduler prioritizes copy-edge autoscroll over the live-output cadence.
  • A focused check confirmed that concurrent streaming output is redrawn every 60 ms instead of every 16 ms under the default 60 fps configuration.
  • This is a non-blocking responsiveness concern, but preserving the faster redraw cadence would avoid visibly slowing live transcript updates during a drag selection.

Reviews (1) · Last reviewed commit: "test(tui): cover the drag autoscroll rat..."

Comment on lines +431 to +432
if state.copy_selection_edge_autoscroll_active() {
return REDRAW_COPY_AUTOSCROLL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Artifacts

Evidence from the check

  • Temporary script injects and runs a focused Rust test, then restores the test sources with an exit trap; it directly verifies the scheduling branch.

Command output from the check

  • Captured output from the executed focused test records the normal 60fps live-output interval as 16ms, establishing the comparison baseline.

Command output from the check

  • Captured successful test output shows one passing test, with live output plus active copy edge autoscroll returning 60ms; the claim is confirmed.

View artifacts

T-Rex 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!

@github-actions github-actions Bot added area: tui Terminal user interface, rendering, and interactions. type: bug Fixes incorrect or broken behavior. labels Sep 20, 2026
@1jehuang

Copy link
Copy Markdown
Owner

Thanks! Closing in favor of #1400, which fixes #1332 with the narrower change (drag-edge autoscroll gets its own path, wheel momentum untouched) and is now merged. Replacing wheel momentum can be proposed separately if still wanted.

@1jehuang 1jehuang closed this Sep 23, 2026
@zipadoodlez
zipadoodlez deleted the fix/copy-drag-autoscroll-speed branch September 26, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tui Terminal user interface, rendering, and interactions. type: bug Fixes incorrect or broken behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: drag-to-copy edge autoscroll scrolls ~3x too fast and glides after release

2 participants