feat: add line numbers and horizontal scroll to code blocks#704
Conversation
- AgentMarkdown: enable showLineNumbers (for multi-line blocks), wrapLines, line number styling (dimmed, non-selectable), and codeTagProps with whiteSpace:pre for proper horizontal scroll - main.css: add overflow-x:auto to .chat-code-block and code block pre/div containers, add .linenumber styling
Greptile SummaryThis PR adds line numbers to multi-line code blocks and enables independent horizontal scrolling for long lines in the chat's syntax-highlighted code view.
Confidence Score: 4/5The change is a self-contained UI enhancement with no data-path or security implications; it is safe to merge after addressing the style nits. The core logic is straightforward and correct. Three issues exist: the outer Both changed files have minor style/redundancy issues worth cleaning up before merge, with Important Files Changed
|
| .chat-code-block { | ||
| border-radius: 6px; | ||
| overflow: hidden; | ||
| overflow-x: auto; | ||
| margin: 6px 0 !important; |
There was a problem hiding this comment.
overflow: hidden masked by overflow-x: auto
Setting overflow-x: auto immediately after overflow: hidden silently changes the computed value to overflow-x: auto; overflow-y: hidden. The overflow: hidden was placed here to clip children to the border-radius: 6px box (a common CSS idiom). The intent of this PR — scrolling the code area — is already fully satisfied by the overflow-x: auto rule on the inner pre/div selector on line 2969. Because the inner element contains its own overflow, the outer .chat-code-block never actually overflows, making this outer overflow-x: auto redundant. Consider removing the new line here and keeping overflow: hidden intact to preserve the clear original intent.
| showLineNumbers={code.split("\n").length > 1} | ||
| wrapLines={true} |
There was a problem hiding this comment.
wrapLines should be conditional, matching showLineNumbers
wrapLines={true} wraps every source line in an extra <span> block, which adds DOM nodes even for single-line code blocks where showLineNumbers evaluates to false and the line-wrapping spans serve no purpose. Aligning the two props eliminates unnecessary overhead for single-line snippets.
| showLineNumbers={code.split("\n").length > 1} | |
| wrapLines={true} | |
| showLineNumbers={code.split("\n").length > 1} | |
| wrapLines={code.split("\n").length > 1} |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| lineNumberStyle={{ | ||
| minWidth: "2.5em", | ||
| paddingRight: "1em", | ||
| color: "#636d83", | ||
| userSelect: "none", | ||
| textAlign: "right", | ||
| }} |
There was a problem hiding this comment.
Duplicate line-number styles — inline wins, CSS becomes dead code
The five properties declared in lineNumberStyle (minWidth, paddingRight, color, userSelect, textAlign) are identical to the properties in .chat-code-block .linenumber added in main.css. React inline styles have higher specificity than any CSS class rule, so the CSS rule is effectively unreachable and will never be applied. Consider picking one approach — either keep the inline lineNumberStyle and remove the CSS rule, or remove the inline object and rely entirely on the CSS class — to avoid a maintenance footgun where future edits to the CSS silently have no effect.
Feature
Add line numbers to multi-line code blocks and enable independent horizontal scrolling for long lines.
Changes
AgentMarkdown.tsx
showLineNumbers={true}for code blocks with more than one linewrapLines={true}so each line gets its own row with a line numberlineNumberStyle— dimmed (#636d83), non-selectable, right-alignedcodeTagProps={{ style: { whiteSpace: "pre" }}}— preserves formatting and enables horizontal scroll for long linesmain.css
.chat-code-block— addedoverflow-x: autofor horizontal scroll.chat-bubble-agent .chat-code-block pre/div— addedoverflow-x: auto.chat-code-block .linenumber— styling for line number column