@@ -37,6 +37,7 @@ interface IMonacoEditorState {
37
37
editor ?: monacoEditor . editor . IStandaloneCodeEditor ;
38
38
model : monacoEditor . editor . ITextModel | null ;
39
39
visibleLineCount : number ;
40
+ attached : boolean ;
40
41
}
41
42
42
43
// Need this to prevent wiping of the current value on a componentUpdate. react-monaco-editor has that problem.
@@ -56,10 +57,11 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
56
57
private styleObserver : MutationObserver | undefined ;
57
58
private watchingMargin : boolean = false ;
58
59
private throttledUpdateWidgetPosition = throttle ( this . updateWidgetPosition . bind ( this ) , 100 ) ;
60
+ private monacoContainer : HTMLDivElement | undefined ;
59
61
60
62
constructor ( props : IMonacoEditorProps ) {
61
63
super ( props ) ;
62
- this . state = { editor : undefined , model : null , visibleLineCount : - 1 } ;
64
+ this . state = { editor : undefined , model : null , visibleLineCount : - 1 , attached : false } ;
63
65
this . containerRef = React . createRef < HTMLDivElement > ( ) ;
64
66
this . measureWidthRef = React . createRef < HTMLDivElement > ( ) ;
65
67
this . debouncedUpdateEditorSize = debounce ( this . updateEditorSize . bind ( this ) , 150 ) ;
@@ -88,8 +90,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
88
90
this . outermostParent . addEventListener ( 'mouseleave' , this . outermostParentLeave ) ;
89
91
}
90
92
93
+ // Create a dummy DOM node to attach the editor to so that it skips layout.
94
+ this . monacoContainer = document . createElement ( 'div' ) ;
95
+ this . monacoContainer . setAttribute ( 'class' , 'monaco-editor-container' ) ;
96
+
91
97
// Create the editor
92
- const editor = monacoEditor . editor . create ( this . containerRef . current ,
98
+ const editor = monacoEditor . editor . create ( this . monacoContainer ,
93
99
{
94
100
value : this . props . value ,
95
101
language : this . props . language ,
@@ -153,9 +159,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
153
159
// Update our margin to include the correct line number style
154
160
this . updateMargin ( editor ) ;
155
161
156
- // Make sure our suggest and hover windows show up on top of other stuff
157
- this . updateWidgetParent ( editor ) ;
158
-
159
162
// If we're readonly, monaco is not putting the aria-readonly property on the textarea
160
163
// We should do that
161
164
if ( this . props . options . readOnly ) {
@@ -237,7 +240,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
237
240
const measureWidthClassName = this . props . measureWidthClassName ? this . props . measureWidthClassName : 'measure-width-div' ;
238
241
return (
239
242
< div className = 'monaco-editor-outer-container' ref = { this . containerRef } >
240
- < div className = 'monaco-editor-container' />
241
243
< div className = { measureWidthClassName } ref = { this . measureWidthRef } />
242
244
</ div >
243
245
) ;
@@ -371,7 +373,14 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
371
373
if ( this . state . visibleLineCount !== currLineCount ) {
372
374
this . props . lineCountChanged ( currLineCount ) ;
373
375
}
374
- this . setState ( { visibleLineCount : currLineCount } ) ;
376
+ // Make sure to attach to a real dom node.
377
+ if ( ! this . state . attached && this . state . editor && this . monacoContainer ) {
378
+ this . containerRef . current . appendChild ( this . monacoContainer ) ;
379
+
380
+ // Make sure our suggest and hover windows show up on top of other stuff
381
+ this . updateWidgetParent ( this . state . editor ) ;
382
+ }
383
+ this . setState ( { visibleLineCount : currLineCount , attached : true } ) ;
375
384
this . state . editor . layout ( { width, height} ) ;
376
385
377
386
// Also need to update our widget positions
0 commit comments