@@ -136,7 +136,7 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
136136 /**
137137 * The instance of [EditorView](https://codemirror.net/docs/ref/#view.EditorView).
138138 */
139- view ? : EditorView ;
139+ view ! : EditorView ;
140140
141141 private _updateListener = EditorView . updateListener . of ( vu => {
142142 if ( vu . docChanged && ! vu . transactions . some ( tr => tr . annotation ( External ) ) ) {
@@ -179,6 +179,8 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
179179 }
180180
181181 ngOnChanges ( changes : SimpleChanges ) : void {
182+ if ( ! this . view ) return ;
183+
182184 if ( changes [ 'value' ] ) {
183185 this . setValue ( this . value ) ;
184186 }
@@ -222,15 +224,15 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
222224 } ) ;
223225
224226 if ( this . autoFocus ) {
225- this . view ? .focus ( ) ;
227+ this . view . focus ( ) ;
226228 }
227229
228- this . view ? .contentDOM . addEventListener ( 'focus' , ( ) => {
230+ this . view . contentDOM . addEventListener ( 'focus' , ( ) => {
229231 this . _onTouched ( ) ;
230232 this . focus . emit ( ) ;
231233 } ) ;
232234
233- this . view ? .contentDOM . addEventListener ( 'blur' , ( ) => {
235+ this . view . contentDOM . addEventListener ( 'blur' , ( ) => {
234236 this . _onTouched ( ) ;
235237 this . blur . emit ( ) ;
236238 } ) ;
@@ -247,10 +249,10 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
247249 }
248250
249251 ngOnDestroy ( ) : void {
250- this . view ? .destroy ( ) ;
252+ this . view . destroy ( ) ;
251253 }
252254
253- writeValue ( value : string ) : void {
255+ writeValue ( value : any ) : void {
254256 if ( this . view ) {
255257 this . setValue ( value ) ;
256258 }
@@ -271,13 +273,13 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
271273
272274 /** Sets editor's value. */
273275 setValue ( value : string ) {
274- this . view ? .dispatch ( {
276+ this . view . dispatch ( {
275277 changes : { from : 0 , to : this . view . state . doc . length , insert : value } ,
276278 } ) ;
277279 }
278280
279281 private _dispatchEffects ( effects : StateEffect < any > | readonly StateEffect < any > [ ] ) {
280- return this . view ? .dispatch ( { effects } ) ;
282+ return this . view . dispatch ( { effects } ) ;
281283 }
282284
283285 /** Sets the root extensions of the editor. */
0 commit comments