@@ -46,72 +46,106 @@ export class CodeCell extends Disposable {
46
46
) {
47
47
super ( ) ;
48
48
49
- const width = this . viewCell . layoutInfo . editorWidth ;
49
+ const editorHeight = this . calculateInitEditorHeight ( ) ;
50
+ this . initializeEditor ( editorHeight ) ;
51
+ this . registerEditorOptionsListener ( ) ;
52
+ this . registerViewCellStateChange ( ) ;
53
+ this . registerFocusModeTracker ( ) ;
54
+ this . registerEditorLayoutListeners ( ) ;
55
+ this . registerDecorations ( ) ;
56
+ this . registerMouseListener ( ) ;
57
+
58
+ // Render Outputs
59
+ this . _outputContainerRenderer = this . instantiationService . createInstance ( CellOutputContainer , notebookEditor , viewCell , templateData , { limit : 500 } ) ;
60
+ this . _outputContainerRenderer . render ( editorHeight ) ;
61
+ // Need to do this after the intial renderOutput
62
+ if ( this . viewCell . isOutputCollapsed === undefined && this . viewCell . isInputCollapsed === undefined ) {
63
+ this . initialViewUpdateExpanded ( ) ;
64
+ this . viewCell . layoutChange ( { } ) ;
65
+ }
66
+
67
+ this . _register ( this . viewCell . onLayoutInfoRead ( ( ) => {
68
+ this . _outputContainerRenderer . probeHeight ( ) ;
69
+ } ) ) ;
70
+
71
+ this . updateForCollapseState ( ) ;
72
+ }
73
+
74
+ private calculateInitEditorHeight ( ) {
50
75
const lineNum = this . viewCell . lineCount ;
51
76
const lineHeight = this . viewCell . layoutInfo . fontInfo ?. lineHeight || 17 ;
52
77
const editorPadding = this . notebookEditor . notebookOptions . computeEditorPadding ( this . viewCell . internalMetadata ) ;
53
-
54
78
const editorHeight = this . viewCell . layoutInfo . editorHeight === 0
55
79
? lineNum * lineHeight + editorPadding . top + editorPadding . bottom
56
80
: this . viewCell . layoutInfo . editorHeight ;
81
+ return editorHeight ;
82
+ }
57
83
84
+ private initializeEditor ( initEditorHeight : number ) {
85
+ const width = this . viewCell . layoutInfo . editorWidth ;
58
86
this . layoutEditor (
59
87
{
60
88
width : width ,
61
- height : editorHeight
89
+ height : initEditorHeight
62
90
}
63
91
) ;
64
92
65
93
const cts = new CancellationTokenSource ( ) ;
66
94
this . _register ( { dispose ( ) { cts . dispose ( true ) ; } } ) ;
67
- raceCancellation ( viewCell . resolveTextModel ( ) , cts . token ) . then ( model => {
95
+ raceCancellation ( this . viewCell . resolveTextModel ( ) , cts . token ) . then ( model => {
68
96
if ( this . _isDisposed ) {
69
97
return ;
70
98
}
71
99
72
- if ( model && templateData . editor ) {
73
- templateData . editor . setModel ( model ) ;
74
- viewCell . attachTextEditor ( templateData . editor ) ;
100
+ if ( model && this . templateData . editor ) {
101
+ this . templateData . editor . setModel ( model ) ;
102
+ this . viewCell . attachTextEditor ( this . templateData . editor ) ;
75
103
const focusEditorIfNeeded = ( ) => {
76
104
if (
77
- notebookEditor . getActiveCell ( ) === viewCell &&
78
- viewCell . focusMode === CellFocusMode . Editor &&
105
+ this . notebookEditor . getActiveCell ( ) === this . viewCell &&
106
+ this . viewCell . focusMode === CellFocusMode . Editor &&
79
107
( this . notebookEditor . hasEditorFocus ( ) || document . activeElement === document . body ) ) // Don't steal focus from other workbench parts, but if body has focus, we can take it
80
108
{
81
- templateData . editor ?. focus ( ) ;
109
+ this . templateData . editor ?. focus ( ) ;
82
110
}
83
111
} ;
84
112
focusEditorIfNeeded ( ) ;
85
113
86
- const realContentHeight = templateData . editor ?. getContentHeight ( ) ;
87
- if ( realContentHeight !== undefined && realContentHeight !== editorHeight ) {
114
+ const realContentHeight = this . templateData . editor ?. getContentHeight ( ) ;
115
+ if ( realContentHeight !== undefined && realContentHeight !== initEditorHeight ) {
88
116
this . onCellEditorHeightChange ( realContentHeight ) ;
89
117
}
90
118
91
119
focusEditorIfNeeded ( ) ;
92
120
}
93
121
} ) ;
122
+ }
94
123
124
+ private registerEditorOptionsListener ( ) {
95
125
const updateEditorOptions = ( ) => {
96
- const editor = templateData . editor ;
126
+ const editor = this . templateData . editor ;
97
127
if ( ! editor ) {
98
128
return ;
99
129
}
100
130
101
- const isReadonly = notebookEditor . isReadOnly ;
102
- const padding = notebookEditor . notebookOptions . computeEditorPadding ( viewCell . internalMetadata ) ;
131
+ const isReadonly = this . notebookEditor . isReadOnly ;
132
+ const padding = this . notebookEditor . notebookOptions . computeEditorPadding ( this . viewCell . internalMetadata ) ;
103
133
const options = editor . getOptions ( ) ;
104
134
if ( options . get ( EditorOption . readOnly ) !== isReadonly || options . get ( EditorOption . padding ) !== padding ) {
105
- editor . updateOptions ( { readOnly : notebookEditor . isReadOnly , padding : notebookEditor . notebookOptions . computeEditorPadding ( viewCell . internalMetadata ) } ) ;
135
+ editor . updateOptions ( { readOnly : this . notebookEditor . isReadOnly , padding : this . notebookEditor . notebookOptions . computeEditorPadding ( this . viewCell . internalMetadata ) } ) ;
106
136
}
107
137
} ;
108
138
109
139
updateEditorOptions ( ) ;
110
- this . _register ( viewCell . onDidChangeState ( ( e ) => {
140
+ this . _register ( this . viewCell . onDidChangeState ( ( e ) => {
111
141
if ( e . metadataChanged || e . internalMetadataChanged ) {
112
142
updateEditorOptions ( ) ;
113
143
}
144
+ } ) ) ;
145
+ }
114
146
147
+ private registerViewCellStateChange ( ) {
148
+ this . _register ( this . viewCell . onDidChangeState ( ( e ) => {
115
149
if ( e . inputCollapsedChanged || e . outputCollapsedChanged ) {
116
150
this . viewCell . pauseLayout ( ) ;
117
151
const updated = this . updateForCollapseState ( ) ;
@@ -122,10 +156,10 @@ export class CodeCell extends Disposable {
122
156
}
123
157
} ) ) ;
124
158
125
- this . _register ( viewCell . onDidChangeLayout ( ( e ) => {
159
+ this . _register ( this . viewCell . onDidChangeLayout ( ( e ) => {
126
160
if ( e . outerWidth !== undefined ) {
127
- const layoutInfo = templateData . editor . getLayoutInfo ( ) ;
128
- if ( layoutInfo . width !== viewCell . layoutInfo . editorWidth ) {
161
+ const layoutInfo = this . templateData . editor . getLayoutInfo ( ) ;
162
+ if ( layoutInfo . width !== this . viewCell . layoutInfo . editorWidth ) {
129
163
this . onCellWidthChange ( ) ;
130
164
}
131
165
}
@@ -134,26 +168,6 @@ export class CodeCell extends Disposable {
134
168
this . relayoutCell ( ) ;
135
169
}
136
170
} ) ) ;
137
-
138
- this . registerFocusModeTracker ( ) ;
139
- this . registerEditorLayoutListeners ( ) ;
140
- this . registerDecorations ( ) ;
141
- this . registerMouseListener ( ) ;
142
-
143
- // Render Outputs
144
- this . _outputContainerRenderer = this . instantiationService . createInstance ( CellOutputContainer , notebookEditor , viewCell , templateData , { limit : 500 } ) ;
145
- this . _outputContainerRenderer . render ( editorHeight ) ;
146
- // Need to do this after the intial renderOutput
147
- if ( this . viewCell . isOutputCollapsed === undefined && this . viewCell . isInputCollapsed === undefined ) {
148
- this . initialViewUpdateExpanded ( ) ;
149
- this . viewCell . layoutChange ( { } ) ;
150
- }
151
-
152
- this . _register ( this . viewCell . onLayoutInfoRead ( ( ) => {
153
- this . _outputContainerRenderer . probeHeight ( ) ;
154
- } ) ) ;
155
-
156
- this . updateForCollapseState ( ) ;
157
171
}
158
172
159
173
private registerEditorLayoutListeners ( ) {
0 commit comments