Skip to content

Commit 43f5054

Browse files
ignoring errors on syntax errors
1 parent 0da016e commit 43f5054

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)