Skip to content

Commit 1c86dea

Browse files
committed
indent setting
1 parent 92fd7ac commit 1c86dea

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

browser/components/CodeEditor.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,21 @@ export default class CodeEditor extends React.Component {
3939
}
4040
}
4141

42-
componentWillReceiveProps (nextProps) {
43-
// if (nextProps.readOnly !== this.props.readOnly) {
44-
// this.editor.setReadOnly(!!nextProps.readOnly)
45-
// }
46-
}
47-
4842
componentDidMount () {
4943
this.editor = CodeMirror(this.refs.root, {
5044
value: this.props.value,
5145
lineNumbers: true,
5246
lineWrapping: true,
53-
theme: this.props.theme
47+
theme: this.props.theme,
48+
indentUnit: this.props.indentSize,
49+
tabSize: this.props.indentSize,
50+
indentWithTabs: this.props.indentType !== 'space'
5451
})
52+
5553
this.setMode(this.props.mode)
54+
5655
this.editor.on('blur', this.blurHandler)
5756
this.editor.on('change', this.changeHandler)
58-
// editor.setTheme('ace/theme/' + theme)
59-
// editor.setReadOnly(!!this.props.readOnly)
60-
61-
// this.editor.setTabSize(this.props.indentSize)
62-
// this.editor.setTabSize(this.props.indentSize)
63-
// session.setUseSoftTabs(this.props.indentType === 'space')
64-
// session.setTabSize(this.props.indentSize)
65-
// session.setUseWrapMode(true)
6657
}
6758

6859
componentWillUnmount () {
@@ -86,15 +77,17 @@ export default class CodeEditor extends React.Component {
8677
needRefresh = true
8778
}
8879

80+
if (prevProps.indentSize !== this.props.indentSize) {
81+
this.editor.setOption('indentUnit', this.props.indentSize)
82+
this.editor.setOption('tabSize', this.props.indentSize)
83+
}
84+
if (prevProps.indentType !== this.props.indentType) {
85+
this.editor.setOption('indentWithTabs', this.props.indentType !== 'space')
86+
}
87+
8988
if (needRefresh) {
9089
this.editor.refresh()
9190
}
92-
// if (prevProps.indentSize !== this.props.indentSize) {
93-
// session.setTabSize(this.props.indentSize)
94-
// }
95-
// if (prevProps.indentType !== this.props.indentType) {
96-
// session.setUseSoftTabs(this.props.indentType === 'space')
97-
// }
9891
}
9992

10093
setMode (mode) {

0 commit comments

Comments
 (0)