From d1576bb6612a159c4f9550667d344acc7aa6991b Mon Sep 17 00:00:00 2001 From: catarak Date: Wed, 7 Sep 2016 15:05:25 -0400 Subject: [PATCH] add css and html beautify --- client/modules/IDE/components/Editor.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/components/Editor.js b/client/modules/IDE/components/Editor.js index 400aa3f3..6f598d41 100644 --- a/client/modules/IDE/components/Editor.js +++ b/client/modules/IDE/components/Editor.js @@ -1,7 +1,9 @@ import React, { PropTypes } from 'react'; import EditorAccessibility from '../components/EditorAccessibility'; import CodeMirror from 'codemirror'; -import beautify from 'js-beautify'; +import beautifyJS from 'js-beautify'; +const beautifyCSS = beautifyJS.css; +const beautifyHTML = beautifyJS.html; import 'codemirror/mode/javascript/javascript'; import 'codemirror/mode/css/css'; import 'codemirror/mode/htmlmixed/htmlmixed'; @@ -69,9 +71,19 @@ class Editor extends React.Component { this._cm.on('keydown', (_cm, e) => { if (e.key === 'Tab' && e.shiftKey) { - _cm.doc.setValue(beautify(_cm.doc.getValue(), - { indent_size: this.props.indentationAmount, - indent_with_tabs: this.props.isTabIndent })); + const beautifyOptions = { + indent_size: this.props.indentationAmount, + indent_with_tabs: this.props.isTabIndent + }; + + const mode = _cm.getOption('mode'); + if (mode === 'javascript') { + _cm.doc.setValue(beautifyJS(_cm.doc.getValue(), beautifyOptions)); + } else if (mode === 'css') { + _cm.doc.setValue(beautifyCSS(_cm.doc.getValue(), beautifyOptions)); + } else if (mode === 'htmlmixed') { + _cm.doc.setValue(beautifyHTML(_cm.doc.getValue(), beautifyOptions)); + } } }); }