Commit aff4c25
authored
markdown: Restore horizontal scrollbars for codeblocks (#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 #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 #34224
### Release Notes:
- AI: Show horizontal scroll-bars in wide markdown elements1 parent 146e754 commit aff4c25
1 file changed
+112
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
| |||
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
| 204 | + | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
207 | 226 | | |
208 | 227 | | |
209 | 228 | | |
| |||
754 | 773 | | |
755 | 774 | | |
756 | 775 | | |
757 | | - | |
758 | | - | |
759 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
760 | 783 | | |
761 | 784 | | |
762 | 785 | | |
763 | 786 | | |
764 | 787 | | |
| 788 | + | |
765 | 789 | | |
766 | 790 | | |
767 | 791 | | |
| |||
841 | 865 | | |
842 | 866 | | |
843 | 867 | | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
844 | 876 | | |
845 | 877 | | |
846 | 878 | | |
847 | 879 | | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
853 | 911 | | |
854 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
855 | 916 | | |
856 | 917 | | |
857 | 918 | | |
858 | | - | |
| 919 | + | |
859 | 920 | | |
860 | 921 | | |
861 | | - | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
862 | 926 | | |
863 | 927 | | |
864 | 928 | | |
865 | 929 | | |
866 | 930 | | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | 931 | | |
878 | 932 | | |
879 | 933 | | |
| |||
884 | 938 | | |
885 | 939 | | |
886 | 940 | | |
887 | | - | |
| 941 | + | |
888 | 942 | | |
889 | 943 | | |
890 | 944 | | |
891 | 945 | | |
892 | 946 | | |
893 | 947 | | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
894 | 969 | | |
895 | 970 | | |
896 | | - | |
| 971 | + | |
897 | 972 | | |
898 | 973 | | |
899 | 974 | | |
900 | | - | |
| 975 | + | |
901 | 976 | | |
902 | 977 | | |
903 | 978 | | |
904 | 979 | | |
905 | 980 | | |
906 | 981 | | |
| 982 | + | |
907 | 983 | | |
908 | 984 | | |
909 | 985 | | |
910 | 986 | | |
911 | 987 | | |
912 | | - | |
913 | | - | |
914 | 988 | | |
915 | 989 | | |
916 | 990 | | |
| |||
1218 | 1292 | | |
1219 | 1293 | | |
1220 | 1294 | | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
1221 | 1304 | | |
1222 | 1305 | | |
1223 | 1306 | | |
| |||
0 commit comments