From 506c959f8cedad1f21a1a1c9c7e5b13b2cbb4380 Mon Sep 17 00:00:00 2001 From: catarak Date: Wed, 7 Sep 2016 12:16:26 -0400 Subject: [PATCH] map shift+tab to beautifier, only for js --- client/modules/IDE/components/Editor.js | 14 +++++++++++++- package.json | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/components/Editor.js b/client/modules/IDE/components/Editor.js index 8b2bd924..400aa3f3 100644 --- a/client/modules/IDE/components/Editor.js +++ b/client/modules/IDE/components/Editor.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import EditorAccessibility from '../components/EditorAccessibility'; import CodeMirror from 'codemirror'; +import beautify from 'js-beautify'; import 'codemirror/mode/javascript/javascript'; import 'codemirror/mode/css/css'; import 'codemirror/mode/htmlmixed/htmlmixed'; @@ -65,6 +66,14 @@ class Editor extends React.Component { this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`; this._cm.setOption('indentWithTabs', this.props.isTabIndent); this._cm.setOption('tabSize', this.props.indentationAmount); + + 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 })); + } + }); } componentDidUpdate(prevProps) { @@ -100,7 +109,10 @@ class Editor extends React.Component { render() { return ( -
+