From 1c86dea4be17bf83b945baafb91635c412c3f2c2 Mon Sep 17 00:00:00 2001 From: Dick Choi Date: Tue, 4 Oct 2016 11:09:27 +0900 Subject: [PATCH] indent setting --- browser/components/CodeEditor.js | 35 +++++++++++++------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index fb5b6646..d721d614 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -39,30 +39,21 @@ export default class CodeEditor extends React.Component { } } - componentWillReceiveProps (nextProps) { - // if (nextProps.readOnly !== this.props.readOnly) { - // this.editor.setReadOnly(!!nextProps.readOnly) - // } - } - componentDidMount () { this.editor = CodeMirror(this.refs.root, { value: this.props.value, lineNumbers: true, lineWrapping: true, - theme: this.props.theme + theme: this.props.theme, + indentUnit: this.props.indentSize, + tabSize: this.props.indentSize, + indentWithTabs: this.props.indentType !== 'space' }) + this.setMode(this.props.mode) + this.editor.on('blur', this.blurHandler) this.editor.on('change', this.changeHandler) - // editor.setTheme('ace/theme/' + theme) - // editor.setReadOnly(!!this.props.readOnly) - - // this.editor.setTabSize(this.props.indentSize) - // this.editor.setTabSize(this.props.indentSize) - // session.setUseSoftTabs(this.props.indentType === 'space') - // session.setTabSize(this.props.indentSize) - // session.setUseWrapMode(true) } componentWillUnmount () { @@ -86,15 +77,17 @@ export default class CodeEditor extends React.Component { needRefresh = true } + if (prevProps.indentSize !== this.props.indentSize) { + this.editor.setOption('indentUnit', this.props.indentSize) + this.editor.setOption('tabSize', this.props.indentSize) + } + if (prevProps.indentType !== this.props.indentType) { + this.editor.setOption('indentWithTabs', this.props.indentType !== 'space') + } + if (needRefresh) { this.editor.refresh() } - // if (prevProps.indentSize !== this.props.indentSize) { - // session.setTabSize(this.props.indentSize) - // } - // if (prevProps.indentType !== this.props.indentType) { - // session.setUseSoftTabs(this.props.indentType === 'space') - // } } setMode (mode) {