Skip to content

markdown_preview: Keep content anchored when search bar opens#55008

Closed
tkilaker wants to merge 2 commits into
zed-industries:mainfrom
tkilaker:markdown_preview-search-bar-anchor
Closed

markdown_preview: Keep content anchored when search bar opens#55008
tkilaker wants to merge 2 commits into
zed-industries:mainfrom
tkilaker:markdown_preview-search-bar-anchor

Conversation

@tkilaker

Copy link
Copy Markdown
Contributor

Summary

  • Adds SearchableItem::search_bar_visibility_changed to MarkdownPreviewView, mirroring the editor's expect_bounds_change pattern.
  • Anchors visible content at the same screen y when the buffer search bar deploys or dismisses, instead of letting it slide by the toolbar's growth.
  • The compensation is deferred via two chained window.on_next_frame callbacks because the first fires before the upcoming draw — the second sees the post-paint bounds. Subtracts the top delta from ScrollHandle::offset.y (which is non-positive when scrolled down) to scroll further down by exactly the toolbar's growth, holding content's screen position constant.

Same root cause as the editor's crates/editor/src/scroll/autoscroll.rs:138 compensation — ScrollHandle::offset.y has the opposite sign convention from the editor's scroll_position.y, so we subtract instead of add.

Fixes #54987.

Test plan

  • Compiles with cargo clippy -p markdown_preview -- --deny warnings.
  • Manual: open Cmd-F mid-document — content stays at same screen y; close + reopen returns offset to its original value (round-trip exact).
  • Manual: at top of doc (offset.y == 0), no compensation runs (mirrors the editor's guard).

Release Notes:

  • Fixed markdown preview content shifting when toggling buffer search

Mirror the editor's `expect_bounds_change` pattern in
`SearchableItem::search_bar_visibility_changed`: snapshot the preview's
pre-toggle `bounds.top()`, then on the second `window.on_next_frame`
(after the toolbar-grown frame has been painted) subtract the top
delta from `scroll_handle.offset().y`. Matches the diff direction the
editor uses at `crates/editor/src/scroll/autoscroll.rs:138`, accounting
for `ScrollHandle::offset.y` being non-positive when scrolled down.

Fixes zed-industries#54987.
@cla-bot

cla-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @tkilaker on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 27, 2026
@tkilaker

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 27, 2026
@cla-bot

cla-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@tkilaker tkilaker closed this Apr 27, 2026
pull Bot pushed a commit to Jaleel-zhu/zed that referenced this pull request May 15, 2026
…industries#55009)

## Summary

- Changes the outer `MarkdownPreviewView` div from `.size_full()` to
`.w_full().flex_1().min_h_0()`.
- Before: preview's height stayed at 100% of the pane regardless of
toolbar size, so deploying the buffer search bar pushed the preview's
bottom 45px past the pane edge — clipped by the pane's
`overflow_hidden`.
- After: preview takes only the leftover main-axis space and shrinks as
the toolbar grows. Bottom edge stays at the pane bottom.

Verified empirically: `bounds.size.height` round-trips `952px ↔ 907px`
with the toolbar at `67 ↔ 112` (Δ = 45px = the search bar's height).

Companion to zed-industries#55008 (anchor compensation). Both PRs come out of
investigating zed-industries#54987 — they fix two independent bugs that surface
together when toggling the search bar.

## Test plan

- [x] Compiles with `cargo clippy -p markdown_preview -- --deny
warnings`.
- [x] Manual: `Cmd-F` in the markdown preview no longer clips bottom
content past the pane edge.
- [x] Manual: `Esc` restores the preview to full available height.

Release Notes:

- Fixed markdown preview content being clipped past the pane edge when
the buffer search bar is open

Co-authored-by: Agus Zubiaga <agus@zed.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search bars should not scroll down content on buffers or Markdown preview

1 participant