Skip to content

Count a narrow compose pane's rows at the width it draws them - #3772

Open
sinelaw wants to merge 2 commits into
masterfrom
ccr-783c7247-2jcxvs-scroll-sync
Open

sinelaw wants to merge 2 commits into
masterfrom
ccr-783c7247-2jcxvs-scroll-sync

Conversation

@sinelaw

@sinelaw sinelaw commented Nov 17, 2026

Copy link
Copy Markdown
Owner

The bug: in the Markdown dual view, scrolling the preview with the wheel stalls inside a drawn code block. Notch after notch moves nothing on screen. Because the source pane syncs to the preview, the preview can also snap back several rows, so it can't be scrolled smoothly past a diagram.

Cause:

  • The wheel and the scroll sync step through the pane's row index.
  • That index was keyed by a geometry that wraps every pane at its width minus the line-number gutter.
  • A compose pane actually lays text out in the compose layout's area, and keeps the gutter only when the desk margin has room for it (resolve_gutter_layout).
  • A preview narrower than its compose width, like each half of the dual view, has no margin. It drops the gutter and draws at the full width.
  • So a drawing framed to that width counted as 2 rows per line in the index but drew as 1. The scroll stepped through rows that weren't on screen.

Fix:

  • A new wrap_area_for gives the width and gutter a pane lays its text out at, resolved the same way the renderer does.
  • The wrap-index geometry and the scrollbar's row counts both use it.
  • Source panes keep the width they had.

Test: the_wheel_scrolls_a_dual_preview_a_row_a_notch_through_a_drawing, in markdown_compose_mermaid_latex.rs. It sets the wheel to 1 line per notch and scrolls the preview of a dual view through an 8-row drawing.

  • Before: ROW 1, ROW 1, ROW 2, ROW 2, ROW 3, ROW 3, ROW 4…
  • After: one row per notch.

Checks:

  • Unit tests pass: 2,768.

  • The markdown, scroll, wrap, compose and sync e2e tests pass: 754.

  • One terminal-scrollback test failed once under that parallel run. It passes on its own, both with and without this change.

  • cargo fmt is clean, and cargo clippy shows no warnings in the changed files.

  • I agree my contributions are licensed under GPL-3.0-or-later and may be relicensed in the future at the maintainer's discretion (see CONTRIBUTING.md).


Generated by Claude Code

In the Markdown dual view, the wheel over the preview stalled inside a
drawn code block: notch after notch moved nothing on screen, and with the
source pane syncing to it the preview could snap back several rows, so it
could not be scrolled smoothly past a diagram.

The row index the wheel and the scroll sync step through was keyed by a
geometry that wrapped every pane at its width less the line-number gutter.
A compose pane lays its text out in the compose layout's area instead, and
keeps the gutter only where the desk margin has room for it; a preview
narrower than its compose width, like each half of the dual view, has no
margin, so it drops the gutter and draws at the full width. A drawing
framed to that width counted as two rows a line in the index and drew as
one, and the scroll stepped through rows that were not on screen.

`wrap_area_for` now states the width and gutter a pane lays text out at,
the way `resolve_gutter_layout` resolves them for the frame, and the wrap
index geometry and the scrollbar's row counts both read it. Source panes
keep the width they had.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012MC4RTeiS6hZV3vHLXYqD9
The dual view's preview still could not be scrolled through a drawing:
each wheel notch moved it a row, and the frames after it put it back.

The preview is taller than the source, so a notch can stop it between two
positions of the source (`inverse_synced_top`), and the source stays put.
The frame after, the focused source pane drives the sync; the guard for "the
focus moved and nothing has scrolled" kept the pair, but recorded the source
as the driver. On the next frame the source drove again, that guard no
longer applied, and the preview was re-derived from the source's top: back
onto the curve, a row or more above where the wheel left it. Any redraw or
idle tick did it, so a notch lasted a frame or two.

A sync now leaves the pair where it is whenever nothing has moved since the
last one, whichever pane drove it. The regression test renders idle frames
after each notch, which is what exposed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012MC4RTeiS6hZV3vHLXYqD9

This branch has not been deployed

No deployments
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