Skip to content

fix(editor): smooth distant cursor reveals - #325

Merged
fcoury merged 1 commit into
mainfrom
fcoury/viewport-reveal
Aug 23, 2026
Merged

fcoury merged 1 commit into
mainfrom
fcoury/viewport-reveal

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Large insertions and other operations that move the cursor offscreen currently put the destination at the top of the viewport. That makes pasted or generated content appear to jump away from its insertion point, and the same rough transition affects formatting, mark jumps, substitute confirmation, and multiline completion.

This adds one shared Vim-like cursor reveal policy:

  • preserve the viewport when the destination is already safely visible
  • minimally scroll nearby destinations into the configured scrolloff margin
  • center distant destinations, including wrapped display rows
  • backfill at EOF instead of leaving a mostly blank viewport
  • keep manual wheel scrolling and undo/redo viewport snapshots authoritative

Tests cover bracketed paste, gq reflow, mark jumps, substitute confirmation, multiline completion, wrapped rows, nearby scrolling, EOF backfill, and manual-scroll regression behavior.

How to Test

  1. Open a file with at least 80 lines, place the cursor around line 20, enter insert mode, and paste roughly 40 newline-terminated lines.
    • Expected: the insertion endpoint remains near the middle of the viewport instead of becoming its top row.
  2. Undo and redo that paste.
    • Expected: undo restores the original cursor and viewport exactly; redo restores the centered post-paste viewport.
  3. Jump to a mark just outside the viewport, then to one more than a viewport away, and finally to EOF.
    • Expected: the nearby jump scrolls only to the scrolloff boundary, the distant jump centers, and EOF is backfilled with the final line at the bottom.
  4. Paste a long single line in a narrow wrapped window.
    • Expected: the destination wrapped segment is centered and remains visible.
  5. Run the focused parity tests:
    • bracketed_paste_reveals_a_distant_endpoint_without_pin_to_top
    • format_gqq_centers_a_distant_reflow_endpoint
    • multiline_completion_centers_a_distant_endpoint
    • distant_mark_jump_centers_the_destination_like_neovim
    • nearby_cursor_reveal_scrolls_only_enough_for_scrolloff
    • distant_cursor_reveal_backfills_the_viewport_at_eof
    • distant_insert_centers_a_wrapped_segment

Validated with cargo clippy --all-targets --all-features -- -D warnings, the full movement and completion suites, the editing suite excluding one unchanged baseline stack-budget overflow, and navigation frame-equivalence tests.

@fcoury
fcoury merged commit be96c53 into main Aug 23, 2026
10 checks passed
@fcoury
fcoury deleted the fcoury/viewport-reveal branch August 23, 2026 03:39
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