Skip to content

Conversation

@xipeng-jin
Copy link
Contributor

@xipeng-jin xipeng-jin commented Oct 20, 2025

Summary

Restore the agent pane’s code-block horizontal scrollbar for easier scrolling without trackpad and preserve individual scroll state across multiple code blocks.

Motivation

Addresses #34224, where agent responses with wide code snippets couldn’t be scrolled horizontally in the panel. Previously there is no visual effect for scrollbar to let the user move the code snippet and it was not obviously to use trackpad or hold down shift while scrolling. This PR will ensure the user being able to only use their mouse to drag the horizontal scrollbar to show the complete line when the code overflow the width of code block.

Changes

  • Support auto-hide horizontal scrollbar for rendering code block in agent panel by adding scrollbar support in markdown.rs
  • Add code_block_scroll_handles cache in crates/markdown/src/markdown.rs to give each code block a persistent ScrollHandle.
  • Wrap rendered code blocks with custom horizontal scrollbars that match the vertical scrollbar styling and track hover visibility.
  • Retain or clear scroll handles based on whether horizontal overflow is enabled, preventing leaks when the markdown re-renders.

How to Test

  1. Open the agent panel, request code generation, and ensure wide snippets show a horizontal scrollbar on hover.
  2. Scroll horizontally, navigate away (e.g., change tabs or trigger a re-render), and confirm the scroll position sticks when returning.
  3. Toggle horizontal overflow styling off/on (if applicable) and verify scrollbars appear or disappear appropriately.

Screenshots / Demos (if UI change)

Screen.Recording.2025-10-20.at.3.54.35.PM.mov

Notes for Reviewers

  • This is my first time contribution for zed, sorry for any code patten inconsistency. So please let me know if you have any comments and suggestions to make the code pattern consistent and easy to maintain.
  • For now, the horizontal scrollbar is not configurable from the setting and the style is fixed with the same design as the vertical one. I am happy to readjust this setting to fit the needs.
  • Please let me know if you think any behaviors or designs need to be changed for the scrollbar.
  • All changes live inside crates/markdown/src/markdown.rs; no API surface changes.

Closes #34224

Release Notes:

  • AI: Show horizontal scroll-bars in wide markdown elements
@cla-bot
Copy link

cla-bot bot commented Oct 20, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @xipeng-jin 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'.

@xipeng-jin
Copy link
Contributor Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 20, 2025
@cla-bot
Copy link

cla-bot bot commented Oct 20, 2025

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

@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Oct 20, 2025
@zed-industries-bot
Copy link

zed-industries-bot commented Oct 21, 2025

Messages
📖

This PR includes links to the following GitHub Issues: #34224
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against fb89abe

@xipeng-jin xipeng-jin force-pushed the issue/agent-pane-code-scroll branch from 51af21b to 4df87cd Compare October 21, 2025 17:09
@xipeng-jin xipeng-jin marked this pull request as draft October 21, 2025 19:47
@xipeng-jin xipeng-jin force-pushed the issue/agent-pane-code-scroll branch from 4df87cd to 4f915a3 Compare October 22, 2025 03:37
@xipeng-jin xipeng-jin marked this pull request as ready for review October 22, 2025 04:09
@danilo-leal danilo-leal changed the title Restore the agent pane’s code-block horizontal scrollbar Oct 22, 2025
cx,
);

let mut parent_container: AnyDiv = if let Some(scroll_handle) =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the desire way to give the default horizontal scrollbar option with CodeBlockRenderer::Custom type. This will add the scrollbar on top of the parent_container on default, so the following transform function might not work as previous design. I am happy to hear any opinions on this. Thanks

@bennetbo bennetbo self-assigned this Nov 3, 2025
@ConradIrwin ConradIrwin enabled auto-merge (squash) November 5, 2025 19:07
@ConradIrwin
Copy link
Member

Thanks for this!

Looks like we can/should get rid of the Custom markdown code block renderer, but that can be a separate PR.

@ConradIrwin ConradIrwin merged commit aff4c25 into zed-industries:main Nov 7, 2025
24 checks passed
@xipeng-jin
Copy link
Contributor Author

Thank you very much for helping me fix the CI tests issue and merged this PR. As @ConradIrwin mentioned, we can probably get rid of the CodeBlockRenderer::Custom option since there is no usage of it. I will create a separate PR to follow up on this. Thanks again.

tomatitito pushed a commit to tomatitito/zed that referenced this pull request Nov 7, 2025
…s#40736)

### Summary

Restore the agent pane’s code-block horizontal scrollbar for easier
scrolling without trackpad and preserve individual scroll state across
multiple code blocks.

### Motivation

Addresses zed-industries#34224, where
agent responses with wide code snippets couldn’t be scrolled
horizontally in the panel. Previously there is no visual effect for
scrollbar to let the user move the code snippet and it was not obviously
to use trackpad or hold down `shift` while scrolling. This PR will
ensure the user being able to only use their mouse to drag the
horizontal scrollbar to show the complete line when the code overflow
the width of code block.

### Changes

- Support auto-hide horizontal scrollbar for rendering code block in
agent panel by adding scrollbar support in markdown.rs
- Add `code_block_scroll_handles` cache in
_crates/markdown/src/markdown.rs_ to give each code block a persistent
`ScrollHandle`.
- Wrap rendered code blocks with custom horizontal scrollbars that match
the vertical scrollbar styling and track hover visibility.
- Retain or clear scroll handles based on whether horizontal overflow is
enabled, preventing leaks when the markdown re-renders.

### How to Test

1. Open the agent panel, request code generation, and ensure wide
snippets show a horizontal scrollbar on hover.
3. Scroll horizontally, navigate away (e.g., change tabs or trigger a
re-render), and confirm the scroll position sticks when returning.
5. Toggle horizontal overflow styling off/on (if applicable) and verify
scrollbars appear or disappear appropriately.

### Screenshots / Demos (if UI change)


https://github.com/user-attachments/assets/e23f94d9-8fe3-42f5-8f77-81b1005a14c8

### Notes for Reviewers

- This is my first time contribution for `zed`, sorry for any code
patten inconsistency. So please let me know if you have any comments and
suggestions to make the code pattern consistent and easy to maintain.
- For now, the horizontal scrollbar is not configurable from the setting
and the style is fixed with the same design as the vertical one. I am
happy to readjust this setting to fit the needs.
- Please let me know if you think any behaviors or designs need to be
changed for the scrollbar.
- All changes live inside _crates/markdown/src/markdown.rs_; no API
surface changes.

Closes zed-industries#34224 

### Release Notes:

- AI: Show horizontal scroll-bars in wide markdown elements
bennetbo pushed a commit that referenced this pull request Nov 8, 2025
Follow up #40736

Clean up `CodeBlockRenderer::Custom` related rendering per the previous
PR
[comment](#40736 (comment)).
Additional note here:
1. The `Custom` variant in the enum `CodeBlockRenderer` will become not
useful since cleaning all code related to the custom rendering logic.
2. Need to further review the usage of code block `metadata` field in
`MarkdownTag::CodeBlock` enum.

I would like to have the team further review my note above so that we
can make sure it will be safe to clean it up and will not affect any
potential future features will be built on top of it. Thank you!

Release Notes:

- N/A
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…s#40736)

### Summary

Restore the agent pane’s code-block horizontal scrollbar for easier
scrolling without trackpad and preserve individual scroll state across
multiple code blocks.

### Motivation

Addresses zed-industries#34224, where
agent responses with wide code snippets couldn’t be scrolled
horizontally in the panel. Previously there is no visual effect for
scrollbar to let the user move the code snippet and it was not obviously
to use trackpad or hold down `shift` while scrolling. This PR will
ensure the user being able to only use their mouse to drag the
horizontal scrollbar to show the complete line when the code overflow
the width of code block.

### Changes

- Support auto-hide horizontal scrollbar for rendering code block in
agent panel by adding scrollbar support in markdown.rs
- Add `code_block_scroll_handles` cache in
_crates/markdown/src/markdown.rs_ to give each code block a persistent
`ScrollHandle`.
- Wrap rendered code blocks with custom horizontal scrollbars that match
the vertical scrollbar styling and track hover visibility.
- Retain or clear scroll handles based on whether horizontal overflow is
enabled, preventing leaks when the markdown re-renders.

### How to Test

1. Open the agent panel, request code generation, and ensure wide
snippets show a horizontal scrollbar on hover.
3. Scroll horizontally, navigate away (e.g., change tabs or trigger a
re-render), and confirm the scroll position sticks when returning.
5. Toggle horizontal overflow styling off/on (if applicable) and verify
scrollbars appear or disappear appropriately.

### Screenshots / Demos (if UI change)


https://github.com/user-attachments/assets/e23f94d9-8fe3-42f5-8f77-81b1005a14c8

### Notes for Reviewers

- This is my first time contribution for `zed`, sorry for any code
patten inconsistency. So please let me know if you have any comments and
suggestions to make the code pattern consistent and easy to maintain.
- For now, the horizontal scrollbar is not configurable from the setting
and the style is fixed with the same design as the vertical one. I am
happy to readjust this setting to fit the needs.
- Please let me know if you think any behaviors or designs need to be
changed for the scrollbar.
- All changes live inside _crates/markdown/src/markdown.rs_; no API
surface changes.

Closes zed-industries#34224 

### Release Notes:

- AI: Show horizontal scroll-bars in wide markdown elements
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…es#42211)

Follow up zed-industries#40736

Clean up `CodeBlockRenderer::Custom` related rendering per the previous
PR
[comment](zed-industries#40736 (comment)).
Additional note here:
1. The `Custom` variant in the enum `CodeBlockRenderer` will become not
useful since cleaning all code related to the custom rendering logic.
2. Need to further review the usage of code block `metadata` field in
`MarkdownTag::CodeBlock` enum.

I would like to have the team further review my note above so that we
can make sure it will be safe to clean it up and will not affect any
potential future features will be built on top of it. Thank you!

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

5 participants