Skip to content

Commit 57d7127

Browse files
authored
Merge branch 'develop' into bug/extra-dot
2 parents 4618ef7 + b6068b5 commit 57d7127

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

client/modules/IDE/components/AddToCollectionSketchList.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class SketchList extends React.Component {
5252
};
5353

5454
inCollection = (sketch) =>
55-
this.props.collection.items.find((item) => item.project.id === sketch.id) !=
56-
null;
55+
this.props.collection.items.find((item) =>
56+
item.isDeleted ? false : item.project.id === sketch.id
57+
) != null;
5758

5859
render() {
5960
const hasSketches = this.props.sketches.length > 0;

client/modules/IDE/components/Editor.jsx

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import CodeMirror from 'codemirror';
44
import emmet from '@emmetio/codemirror-plugin';
5-
import beautifyJS from 'js-beautify';
5+
import prettier from 'prettier';
6+
import babelParser from 'prettier/parser-babel';
7+
import htmlParser from 'prettier/parser-html';
8+
import cssParser from 'prettier/parser-postcss';
69
import { withTranslation } from 'react-i18next';
710
import 'codemirror/mode/css/css';
811
import 'codemirror/addon/selection/active-line';
@@ -59,14 +62,10 @@ import * as ConsoleActions from '../actions/console';
5962

6063
emmet(CodeMirror);
6164

62-
const beautifyCSS = beautifyJS.css;
63-
const beautifyHTML = beautifyJS.html;
64-
6565
window.JSHINT = JSHINT;
6666
window.CSSLint = CSSLint;
6767
window.HTMLHint = HTMLHint;
6868

69-
const IS_TAB_INDENT = false;
7069
const INDENTATION_AMOUNT = 2;
7170

7271
class Editor extends React.Component {
@@ -335,31 +334,33 @@ class Editor extends React.Component {
335334
this._cm.execCommand('replace');
336335
}
337336

337+
prettierFormatWithCursor(parser, plugins) {
338+
try {
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+
this._cm.focus();
349+
this._cm.doc.setCursor(this._cm.doc.posFromIndex(cursorOffset));
350+
} catch (error) {
351+
console.error(error);
352+
}
353+
}
354+
338355
tidyCode() {
339-
const beautifyOptions = {
340-
indent_size: INDENTATION_AMOUNT,
341-
indent_with_tabs: IS_TAB_INDENT
342-
};
343356
const mode = this._cm.getOption('mode');
344-
const currentPosition = this._cm.doc.getCursor();
345357
if (mode === 'javascript') {
346-
this._cm.doc.setValue(
347-
beautifyJS(this._cm.doc.getValue(), beautifyOptions)
348-
);
358+
this.prettierFormatWithCursor('babel', [babelParser]);
349359
} else if (mode === 'css') {
350-
this._cm.doc.setValue(
351-
beautifyCSS(this._cm.doc.getValue(), beautifyOptions)
352-
);
360+
this.prettierFormatWithCursor('css', [cssParser]);
353361
} else if (mode === 'htmlmixed') {
354-
this._cm.doc.setValue(
355-
beautifyHTML(this._cm.doc.getValue(), beautifyOptions)
356-
);
362+
this.prettierFormatWithCursor('html', [htmlParser]);
357363
}
358-
this._cm.focus();
359-
this._cm.doc.setCursor({
360-
line: currentPosition.line,
361-
ch: currentPosition.ch + INDENTATION_AMOUNT
362-
});
363364
}
364365

365366
initializeDocuments(files) {

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"postcss-focus": "^4.0.0",
123123
"postcss-loader": "^4.2.0",
124124
"postcss-preset-env": "^6.7.0",
125-
"prettier": "^2.2.1",
126125
"react-test-renderer": "^16.12.0",
127126
"rimraf": "^2.7.1",
128127
"sass-loader": "^10.1.1",
@@ -177,7 +176,6 @@
177176
"i18next-http-backend": "^1.0.21",
178177
"is-url": "^1.2.4",
179178
"jest-express": "^1.11.0",
180-
"js-beautify": "^1.10.3",
181179
"jsdom": "^9.8.3",
182180
"jshint": "^2.11.0",
183181
"lodash": "^4.17.19",
@@ -194,6 +192,7 @@
194192
"passport-google-oauth20": "^1.0.0",
195193
"passport-http": "^0.3.0",
196194
"passport-local": "^1.0.0",
195+
"prettier": "^2.2.1",
197196
"pretty-bytes": "^3.0.1",
198197
"primer-tooltips": "^1.5.11",
199198
"prop-types": "^15.6.2",

0 commit comments

Comments
 (0)