Skip to content

Commit d5c661a

Browse files
committed
[#1223] Move setting cursor offet to prettierFormatWithCursor
1 parent 43f5054 commit d5c661a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,23 @@ class Editor extends React.Component {
346346
}
347347
);
348348
this._cm.doc.setValue(formatted);
349-
return cursorOffset;
349+
if (cursorOffset) {
350+
this._cm.doc.setCursor(this._cm.doc.posFromIndex(cursorOffset));
351+
}
350352
} catch (error) {
351-
return null;
353+
console.error(error);
352354
}
353355
}
354356

355357
tidyCode() {
356358
const mode = this._cm.getOption('mode');
357-
let cursorOffset;
358359
if (mode === 'javascript') {
359-
cursorOffset = this.prettierFormatWithCursor('babel', [babelParser]);
360+
this.prettierFormatWithCursor('babel', [babelParser]);
360361
} else if (mode === 'css') {
361-
cursorOffset = this.prettierFormatWithCursor('css', [cssParser]);
362+
this.prettierFormatWithCursor('css', [cssParser]);
362363
} else if (mode === 'htmlmixed') {
363-
cursorOffset = this.prettierFormatWithCursor('html', [htmlParser]);
364+
this.prettierFormatWithCursor('html', [htmlParser]);
364365
}
365-
this._cm.focus();
366-
if (cursorOffset)
367-
this._cm.doc.setCursor(this._cm.doc.posFromIndex(cursorOffset));
368366
}
369367

370368
initializeDocuments(files) {

0 commit comments

Comments
 (0)