Skip to content

fix(scrollsync): prevent TreeSitter follower redraws from moving the active cursor - #517

Closed
richardgill wants to merge 3 commits into
esmuellert:mainfrom
richardgill:fix-treesitter-scrollbind-cursor-jump
Closed

fix(scrollsync): prevent TreeSitter follower redraws from moving the active cursor#517
richardgill wants to merge 3 commits into
esmuellert:mainfrom
richardgill:fix-treesitter-scrollbind-cursor-jump

Conversation

@richardgill

@richardgill richardgill commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Prevent TreeSitter redraws in a virtual follower buffer from moving the active cursor during structural scroll synchronization, while keeping the follower aligned as it leaves a full-screen filler block.

Root cause

CodeDiff records the expected view after programmatically scrolling a follower pane. TreeSitter can then correct the virtual buffer's final view while rendering a tall virt_lines filler block. The resulting WinScrolled echo previously looked like independent follower scrolling, so CodeDiff promoted that pane to leader and synchronized its clamped position back to the active pane.

An exact follower correction can also be displaced by local scrolloff before the redraw echo arrives, briefly exposing unrelated baseline text.

The regression was introduced by #471, which added structural scroll synchronization.

Changes

  • Track programmatic follower scrolls until their own WinScrolled event arrives.
  • Use the changed window IDs from v:event and the callback match to consume only the relevant follower echo.
  • Record TreeSitter's corrected final follower view without synchronizing it back to the active pane.
  • Temporarily suppress follower scrolloff during exact filler alignment, then restore it on redraw, resume, refresh, or teardown.
  • Preserve subsequent non-focused follower scrolling and move-alignment resume behavior.
  • Add focused coverage for echo ownership, redraw corrections, full-screen filler alignment, stale pending state, and later non-focused scrolling.

Benefits

  • Keeps the active cursor stable around tall filler blocks in TreeSitter-highlighted virtual buffers.
  • Prevents the follower from flashing unrelated baseline text when leaving a full-screen filler.
  • Preserves structural scroll synchronization, non-focused mouse scrolling, and user window options.
  • Avoids disabling TreeSitter or syntax highlighting in revision buffers.

Demonstration

Before

before.mp4

After

after.mp4

@richardgill
richardgill marked this pull request as ready for review August 3, 2026 19:09
@richardgill

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #518, which tracks the underlying TreeSitter/virt_lines follower-view problem and includes the deterministic reproduction and before video. This PR mitigated the cursor jump but was not a complete solution to the underlying redraw correction.

@richardgill richardgill closed this Aug 3, 2026
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.

1 participant