Skip to content

fix(annotations): snap floating quote overlays to device pixels to eliminate scroll jitter - #2079

Merged
Hona merged 2 commits into
devfrom
fix/quote-toolbar-jitter
Dec 1, 2026
Merged

Hona merged 2 commits into
devfrom
fix/quote-toolbar-jitter

Conversation

@Hona

@Hona Hona commented Dec 1, 2026

Copy link
Copy Markdown
Member

Cause

Floating annotation overlays (quote-toolbar, line-comment-toolbar, and quote-comment) render in FLOATING_CHROME outside the scroll container, so they carry no inherited rigid scroll translation. During smooth scrolling (such as slow middle-click autoscroll), cx.selection_rects() and cx.window_layout() move their placement by fractional device pixels every frame:

flowchart LR
  A["Fractional scroll Y (rigid = 0)"] --> B["Outer pill snaps: floor(Y + 0.5)"]
  A --> C["Quote icon snaps: floor(Y + 6s + 0.5)"]
  A --> D["Quote text snaps: round(Y + 4s + baseline)"]
  B --> E["Crosses 0.5 at different frames"]
  C --> E
  D --> E
  E --> F["±1 px internal icon & text jitter"]
Loading
  • At 1.25× and 1.75×, 6s is a half-pixel (7.5, 10.5), causing the quote icon to snap out of phase with the outer pill.
  • At fractional / zoomed scales (1.1×, 1.375×, 1.6×, 1.875×, etc.), both 4s and 6s are non-integer, causing both the Quote label and icon to jitter ±1 px independently inside the pill.
  • Sibling audit found the same fractional-scroll phase drift in line_comments::selection::toolbar (text offset 6 pt, jittering even at 1.25× / 1.75×) and quote::editor::view while riding with scroll (Placing::Riding).

Fix

  • Add snap_device_px(v, origin, scale) in features/annotations/src/lib.rs matching Rune's half-up rounding ((x + 0.5).floor()).
  • Snap quote::toolbar (features/annotations/src/quote/mod.rs) and line_comments::selection::toolbar (features/annotations/src/line_comments/selection.rs) onto whole device pixels at cx.env().scale and apply El::paint_contained([origin + x, origin + y]) so the pill frame, icon, and text baseline share one pixel grid.
  • Snap quote::editor::view's band and target coordinates (features/annotations/src/quote/editor.rs) onto device pixels and apply El::paint_contained while Placing::Riding (preserving sub-pixel spring glides during Placing::Gliding).
pub(crate) fn snap_device_px(v: f32, origin: f32, scale: f32) -> f32 {
    if scale > 0.0 && scale.is_finite() {
        ((origin + v) * scale + 0.5).floor() / scale - origin
    } else {
        v
    }
}

Before / After

Consecutive middle-click autoscroll frames (3× nearest-neighbor zoom), aligned by the outer pill's top border. Red lines mark the pill top and F0/F1 text bounds; red arrows mark ±1 px vertical jumps inside the pill.

Scale Before (±1 px internal jitter) After (0 px drift)
1.375× (125% + 110% zoom) Before 1.375x After 1.375x
1.25× (Windows 125%) Before 1.25x After 1.25x
Target / Scale Before max interior px diff After max interior px diff
quote-toolbar @ 1.0× / 1.5× / 2.0× 0 0
quote-toolbar @ 1.25× / 1.75× 214 (icon ±1 px) 0
quote-toolbar @ 1.1× / 1.375× / 1.6× / 1.875× 214 (icon & text ±1 px) 0
quote-comment @ 1.375× (riding scroll) 138 (preview text ±1 px) 0

Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Hona
Hona merged commit 66bc303 into dev Dec 1, 2026
@Hona
Hona deleted the fix/quote-toolbar-jitter branch December 1, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants