@@ -19,6 +19,7 @@ interface CodeViewProps {
1919
2020export const CodeView : React . FC < CodeViewProps > = ( { label, description, content } ) => {
2121 const [ open , setOpen ] = React . useState < boolean > ( true ) ;
22+ const [ hasExpandableContent , setHasExpandableContent ] = React . useState < boolean > ( false ) ;
2223 const [ expanded , setExpanded ] = React . useState < boolean > ( false ) ;
2324 const [ editor , setEditor ] = React . useState < monaco . editor . IStandaloneCodeEditor | undefined > ( undefined ) ;
2425
@@ -47,7 +48,6 @@ export const CodeView: React.FC<CodeViewProps> = ({ label, description, content
4748 scrollBeyondLastLine : false ,
4849 lineNumbers : 'off' ,
4950 renderLineHighlight : 'none' ,
50- automaticLayout : true ,
5151 fontSize : 12 ,
5252 wordWrap : 'on' ,
5353 rulers : [ ] ,
@@ -57,43 +57,59 @@ export const CodeView: React.FC<CodeViewProps> = ({ label, description, content
5757 } ) ;
5858
5959 setEditor ( editor ) ;
60- updateEditorHeight ( editor ) ;
60+ updateEditorDimensions ( editor ) ;
61+
62+ // Check if content exceeds collapsed height and should show expand button
63+ setHasExpandableContent ( editor . getContentHeight ( ) > collapsedHeight ) ;
64+
65+ // Listen for width changes and relayout editor
66+ let lastObservedWidth = editorContainerRef . current . clientWidth ;
67+ const resizeObserver = new ResizeObserver ( entries => {
68+ const newWidth = entries . at ( 0 ) ?. contentRect . width ;
69+ if ( newWidth && newWidth !== lastObservedWidth ) {
70+ lastObservedWidth = newWidth ;
71+ updateEditorDimensions ( editor , lastObservedWidth ) ;
72+ }
73+ } ) ;
74+ resizeObserver . observe ( editorContainerRef . current ) ;
6175
62- // Cleanup
6376 return ( ) => {
77+ resizeObserver . disconnect ( ) ;
6478 if ( editor ) {
6579 editor . dispose ( ) ;
6680 setEditor ( undefined ) ;
6781 }
6882 } ;
83+
6984 } , [ editorContainerRef ] ) ;
7085
7186 // Update editor height when expanded state changes
7287 React . useEffect ( ( ) => {
7388 if ( editor ) {
74- updateEditorHeight ( editor ) ;
89+ updateEditorDimensions ( editor ) ;
7590 }
7691 } , [ expanded ] ) ;
7792
78- const updateEditorHeight = ( editorInstance : monaco . editor . IStandaloneCodeEditor ) => {
79- if ( ! editorContainerRef . current ) return ;
93+ const updateEditorDimensions = ( editorInstance : monaco . editor . IStandaloneCodeEditor , containerWidthHint ?: number ) => {
94+ if ( ! editorContainerRef . current ) {
95+ return ;
96+ }
8097
8198 const contentHeight = editorInstance . getContentHeight ( ) ;
82- const width = editorContainerRef . current . clientWidth || 300 ;
99+ const width = containerWidthHint ?? ( editorContainerRef . current . clientWidth || 300 ) ;
83100
84101 if ( expanded ) {
85102 if ( editorContainerRef . current ) {
86103 editorContainerRef . current . style . height = `${ contentHeight } px` ;
87104 }
88- editorInstance . layout ( { width, height : contentHeight } ) ;
89105 } else {
90106 const newContentHeight = Math . min ( contentHeight , collapsedHeight ) ;
91107 if ( editorContainerRef . current ) {
92108 editorContainerRef . current . style . height = `${ newContentHeight } px` ;
93109 }
94- // Always lay the editor out for the full height
95- editorInstance . layout ( { width, height : contentHeight } ) ;
96110 }
111+
112+ editorInstance . layout ( { width, height : contentHeight } ) ;
97113 } ;
98114
99115 const toggleExpanded = ( ) => {
@@ -104,9 +120,6 @@ export const CodeView: React.FC<CodeViewProps> = ({ label, description, content
104120 setOpen ( ! open ) ;
105121 } ;
106122
107- // Check if content exceeds collapsed height and should show expand button
108- const hasExpandableContent = editor ? editor . getContentHeight ( ) > collapsedHeight : false ;
109-
110123 return (
111124 < div className = { `codeview-wrapper ${ ! expanded && hasExpandableContent ? 'collapsed' : '' } ` } >
112125 < details className = "codeview-details" open = { open } >
0 commit comments