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 {
336336 }
337337
338338 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+ }
349353 }
350354
351355 tidyCode ( ) {
@@ -359,7 +363,8 @@ class Editor extends React.Component {
359363 cursorOffset = this . prettierFormatWithCursor ( 'html' , [ htmlParser ] ) ;
360364 }
361365 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 ) ) ;
363368 }
364369
365370 initializeDocuments ( files ) {
You can’t perform that action at this time.
0 commit comments