File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed
client/modules/IDE/components Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -336,16 +336,20 @@ class Editor extends React.Component {
336
336
}
337
337
338
338
prettierFormatWithCursor ( parser , plugins ) {
339
- const { formatted, cursorOffset } = prettier . formatWithCursor (
340
- this . _cm . doc . getValue ( ) ,
341
- {
342
- cursorOffset : this . _cm . doc . indexFromPos ( this . _cm . doc . getCursor ( ) ) ,
343
- parser,
344
- plugins
345
- }
346
- ) ;
347
- this . _cm . doc . setValue ( formatted ) ;
348
- return cursorOffset ;
339
+ try {
340
+ const { formatted, cursorOffset } = prettier . formatWithCursor (
341
+ this . _cm . doc . getValue ( ) ,
342
+ {
343
+ cursorOffset : this . _cm . doc . indexFromPos ( this . _cm . doc . getCursor ( ) ) ,
344
+ parser,
345
+ plugins
346
+ }
347
+ ) ;
348
+ this . _cm . doc . setValue ( formatted ) ;
349
+ return cursorOffset ;
350
+ } catch ( error ) {
351
+ return null ;
352
+ }
349
353
}
350
354
351
355
tidyCode ( ) {
@@ -359,7 +363,8 @@ class Editor extends React.Component {
359
363
cursorOffset = this . prettierFormatWithCursor ( 'html' , [ htmlParser ] ) ;
360
364
}
361
365
this . _cm . focus ( ) ;
362
- this . _cm . doc . setCursor ( this . _cm . doc . posFromIndex ( cursorOffset ) ) ;
366
+ if ( cursorOffset )
367
+ this . _cm . doc . setCursor ( this . _cm . doc . posFromIndex ( cursorOffset ) ) ;
363
368
}
364
369
365
370
initializeDocuments ( files ) {
You can’t perform that action at this time.
0 commit comments