@@ -62,9 +62,7 @@ export class StatefullMarkdownCell extends Disposable {
62
62
63
63
// not first time, we don't need to create editor or bind listeners
64
64
viewCell . attachTextEditor ( this . editor ) ;
65
- if ( notebookEditor . getActiveCell ( ) === viewCell ) {
66
- this . editor . focus ( ) ;
67
- }
65
+ this . tryFocusEditor ( ) ;
68
66
69
67
this . bindEditorListeners ( this . editor . getModel ( ) ! ) ;
70
68
} else {
@@ -97,9 +95,7 @@ export class StatefullMarkdownCell extends Disposable {
97
95
}
98
96
99
97
this . editor ! . setModel ( model ) ;
100
- if ( notebookEditor . getActiveCell ( ) === viewCell ) {
101
- this . editor ! . focus ( ) ;
102
- }
98
+ this . tryFocusEditor ( ) ;
103
99
104
100
const realContentHeight = this . editor ! . getContentHeight ( ) ;
105
101
if ( realContentHeight !== editorHeight ) {
@@ -115,7 +111,7 @@ export class StatefullMarkdownCell extends Disposable {
115
111
viewCell . attachTextEditor ( this . editor ! ) ;
116
112
117
113
if ( viewCell . editState === CellEditState . Editing ) {
118
- this . editor ! . focus ( ) ;
114
+ this . tryFocusEditor ( ) ;
119
115
}
120
116
121
117
this . bindEditorListeners ( model , {
@@ -135,7 +131,7 @@ export class StatefullMarkdownCell extends Disposable {
135
131
const totalHeight = editorHeight + 32 + clientHeight + CELL_STATUSBAR_HEIGHT ;
136
132
this . viewCell . totalHeight = totalHeight ;
137
133
notebookEditor . layoutNotebookCell ( viewCell , totalHeight ) ;
138
- this . editor . focus ( ) ;
134
+ this . tryFocusEditor ( ) ;
139
135
renderedEditors . set ( this . viewCell , this . editor ! ) ;
140
136
} else {
141
137
this . viewCell . detachTextEditor ( ) ;
@@ -205,7 +201,7 @@ export class StatefullMarkdownCell extends Disposable {
205
201
206
202
const updateForFocusMode = ( ) => {
207
203
if ( viewCell . focusMode === CellFocusMode . Editor ) {
208
- this . editor ?. focus ( ) ;
204
+ this . tryFocusEditor ( ) ;
209
205
}
210
206
211
207
toggleClass ( templateData . container , 'cell-editor-focus' , viewCell . focusMode === CellFocusMode . Editor ) ;
@@ -247,6 +243,12 @@ export class StatefullMarkdownCell extends Disposable {
247
243
viewUpdate ( ) ;
248
244
}
249
245
246
+ private tryFocusEditor ( ) {
247
+ if ( this . notebookEditor . getActiveCell ( ) === this . viewCell ) {
248
+ this . editor ?. focus ( ) ;
249
+ }
250
+ }
251
+
250
252
private layoutEditor ( dimension : IDimension ) : void {
251
253
this . editor ?. layout ( dimension ) ;
252
254
this . templateData . statusBarContainer . style . width = `${ dimension . width } px` ;
0 commit comments