❌

Lees weergave

nightly: editor: Add optional cursor movement animation (#63195)

Objective

Add an optional smooth cursor movement animation to make cursor position
changes easier to follow, especially during larger jumps and
multi-cursor editing.

Related to #4991.

Solution

  • Add a new cursor_animation.enabled editor setting, disabled by
    default.
  • Animate local bar and block cursors using a damped spring while
    preserving momentum during rapid cursor movement.
  • Support multiple local cursors independently.
  • Continue using the cursor color provided by the active theme.
  • Snap immediately when scrolling, resizing, or other viewport changes
    would make interpolation misleading.
  • Respect the reduce_motion setting.
  • Request animation frames only while an enabled cursor animation is
    active.

Enabling the feature causes additional editor redraws while the cursor
is moving, so it is opt-in and the performance cost is mentioned in the
setting documentation.

Attribution

The cursor spring physics and four-corner deformation algorithm are
adapted from
vscode-neovide-cursor,
which is available under the MIT License and inspired by Neovide.

The implementation adapts the algorithm to Zed's editor and GPUI
architecture, including viewport handling, selection state
reconciliation, multi-cursor support, theme integration, and
reduced-motion behavior. The attribution and license information are
also retained in the source file.

Testing

Automated checks run on Windows:

  • cargo fmt --all --check
  • cargo test -p editor cursor_animation --lib
    • 15 cursor animation tests passed.

The tests cover:

  • Spring convergence.
  • Short and long cursor movements.
  • Mid-animation retargeting and momentum preservation.
  • Multiple independent cursors.
  • Selection replacement and state cleanup.
  • Viewport and scroll changes.
  • Invalid or unusually large timing values.
  • Supported cursor shapes.

To test manually:

  1. Add the following to the settings file:

    "cursor_animation": {
      "enabled": true
    }
  2. Move the cursor using typing, arrow keys, mouse clicks, and
    multi-cursor actions.

  3. Toggle the setting off and confirm that cursor rendering immediately
    returns to its normal behavior.

Manual testing was performed on Windows and Linux using a release build
from this exact PR branch.

Verified that:

  • Cursor animation is disabled by default.
  • Enabling cursor_animation.enabled is hot-reloaded without restarting
    Zed.
  • Disabling the setting immediately restores the original cursor
    behavior.
  • Cursor movement remains responsive during typing, keyboard navigation,
    and mouse navigation.

This exact PR branch has not yet been manually tested on macOS.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards
    (UX/UI
    and
    icon
    guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Showcase

test-github.mp4

Release Notes:

  • Added an optional cursor movement animation setting.

Co-authored-by: Christopher Biscardi chris@christopherbiscardi.com

  •  
❌