mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
4.9 KiB
4.9 KiB
🔧 Code Block Width and Height Fixes
Issues Fixed
1. Code Block Extending Beyond Chat Input
Problem: The code block in live IDE mode was extending beyond the boundaries of the chat input, causing horizontal overflow.
Root Cause:
- The code container was using
inline-flexdisplay - No width constraints were applied
- The
SyntaxHighlightercomponent was not constrained
Solution:
- Changed outer container from
inlinetoblockdisplay withw-full - Added
maxWidth: '100%'andboxSizing: 'border-box'to code container - Added
overflow-x-autofor horizontal scrolling when code is too wide - Applied same constraints to
SyntaxHighlightercustomStyle
2. Text Hidden Behind Toolbar
Problem: When typing in code mode, text could be hidden behind the bottom toolbar.
Root Cause: The code block wasn't properly influencing the chat input's height calculation, so the container didn't expand enough.
Solution:
- The existing
syncDisplayHeightfunction already monitors the display layer - By making the code block a proper block-level element with correct sizing, it now properly contributes to the
scrollHeight - The
containerHeightstate is updated based on the actual content height - This ensures the parent container allocates enough space
Changes Made
RichChatInput.tsx - Code Mode Rendering
return (
<div className="whitespace-pre-wrap relative w-full"> // Added w-full
{/* Text before trigger */}
{textBefore && (
<span className="inline whitespace-pre-wrap">{textBefore}</span>
)}
{/* Language badge */}
<div className="inline-flex items-center gap-1 px-2 py-0.5 mb-1 text-xs font-mono text-gray-300 bg-gray-800 rounded border border-gray-700">
<Code size={12} />
<span>{codeMode.language}</span>
</div>
{/* Code content - NOW PROPERLY CONSTRAINED */}
<div
className="block font-mono text-sm bg-[#1E1E1E]/30 rounded p-2 border border-gray-700/50 mt-1 w-full overflow-x-auto" // Changed to block, added w-full and overflow-x-auto
style={{
fontFamily: 'Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace',
maxWidth: '100%', // Added
boxSizing: 'border-box', // Added
}}
>
<SyntaxHighlighter
language={codeMode.language}
style={vscDarkPlus}
customStyle={{
margin: 0,
padding: 0,
background: 'transparent',
fontSize: '0.875rem',
lineHeight: '1.5',
maxWidth: '100%', // Added
overflowX: 'auto', // Added
}}
PreTag="div"
CodeTag="code"
wrapLines={true}
showLineNumbers={false}
>
{codeContent || ' '}
</SyntaxHighlighter>
{/* Cursor */}
{isFocused && (
<span
className="border-l border-text-default inline-block"
style={{
animation: "blink 1s step-end infinite",
height: "1.3em",
width: "1px",
marginLeft: "2px",
position: "relative"
}}
/>
)}
</div>
</div>
);
How It Works Now
-
Width Constraint:
- The code block is now a block-level element that respects the container width
w-fullensures it takes the full width of the parentmaxWidth: 100%prevents it from exceeding the containerboxSizing: border-boxensures padding is included in width calculations
-
Horizontal Scrolling:
- When code lines are too long,
overflow-x-autoadds a horizontal scrollbar - This prevents the code from breaking the layout
- When code lines are too long,
-
Height Calculation:
- The code block now properly contributes to the display layer's
scrollHeight syncDisplayHeight()detects the increased heightcontainerHeightstate is updated- The parent container expands accordingly
- This prevents text from being hidden behind the toolbar
- The code block now properly contributes to the display layer's
Testing
To verify the fixes:
-
Width Test:
- Type
#pythonin the chat input - Paste or type a very long line of code
- ✅ The code should stay within the chat input boundaries
- ✅ A horizontal scrollbar should appear if needed
- Type
-
Height Test:
- Type
#pythonin the chat input - Type multiple lines of code (10+ lines)
- ✅ The chat input should expand to show all lines
- ✅ No text should be hidden behind the toolbar
- ✅ The container should scroll if it reaches maxHeight
- Type
-
Inline Test:
- Type some text, then
#python, then code - ✅ Text before the trigger should display normally
- ✅ Code block should be properly constrained
- Type some text, then
Related Files
ui/desktop/src/components/RichChatInput.tsx- Main implementationui/desktop/src/components/ChatInput.tsx- Parent component that uses RichChatInput
Commit
commit 83eba3f3a79
Fix code block width constraints and ensure proper height calculation