diff --git a/.gitignore b/.gitignore index 83939792..481960da 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist/ node_modules/ thumbs.db +/.idea diff --git a/src/actions/settings.js b/src/actions/settings.js index 6fdcf6cf..33d969cc 100644 --- a/src/actions/settings.js +++ b/src/actions/settings.js @@ -33,6 +33,9 @@ export function loadSettings() { foldLevel: 1, highlightTag: false, lightTheme: false, + useTab: false, + tabSize: 2, + indentSize: 2, }, mjml: { minify: false, diff --git a/src/components/FileEditor/index.js b/src/components/FileEditor/index.js index ae75998f..56c263da 100644 --- a/src/components/FileEditor/index.js +++ b/src/components/FileEditor/index.js @@ -62,6 +62,9 @@ function beautify(content) { lightTheme: settings.getIn(['editor', 'lightTheme'], false), errors: get(preview, 'errors', []), snippets: settings.get('snippets'), + useTab: settings.getIn(['editor', 'useTab'], false), + tabSize: settings.getIn(['editor', 'tabSize'], 2), + indentSize: settings.getIn(['editor', 'indentSize'], 2), } }, { @@ -120,6 +123,15 @@ class FileEditor extends Component { if (prevProps.lightTheme !== this.props.lightTheme) { this._codeMirror.setOption('theme', this.props.lightTheme ? 'neo' : 'one-dark') } + if (prevProps.useTab !== this.props.useTab) { + this._codeMirror.setOption('indentWithTabs', this.props.useTab) + } + if (prevProps.tabSize !== this.props.tabSize) { + this._codeMirror.setOption('tabSize', this.props.tabSize) + } + if (prevProps.indentSize !== this.props.indentSize) { + this._codeMirror.setOption('indentUnit', this.props.indentSize) + } } componentWillUnmount() { @@ -170,7 +182,14 @@ class FileEditor extends Component { return } - const { wrapLines, highlightTag, lightTheme } = this.props + const { + wrapLines, + highlightTag, + lightTheme, + useTab, + tabSize, + indentSize, + } = this.props if (this._codeMirror) { this._codeMirror.toTextArea() @@ -178,11 +197,11 @@ class FileEditor extends Component { } this._codeMirror = CodeMirror.fromTextArea(this._textarea, { + tabSize, dragDrop: false, matchTags: highlightTag ? { bothTags: true } : undefined, - indentUnit: 2, - tabSize: 2, - indentWithTabs: false, + indentUnit: indentSize, + indentWithTabs: useTab, mode: 'xml', lineNumbers: true, theme: lightTheme ? 'neo' : 'one-dark', diff --git a/src/components/SettingsModal/index.js b/src/components/SettingsModal/index.js index a2c6595e..f77398e9 100644 --- a/src/components/SettingsModal/index.js +++ b/src/components/SettingsModal/index.js @@ -94,6 +94,9 @@ class SettingsModal extends Component { const editorLightTheme = settings.getIn(['editor', 'lightTheme'], false) const minifyOutput = settings.getIn(['mjml', 'minify'], false) const beautifyOutput = settings.getIn(['mjml', 'beautify'], false) + const editorUseTab = settings.getIn(['editor', 'useTab'], false) + const editorTabSize = settings.getIn(['editor', 'tabSize'], 2) + const editorIndentSize = settings.getIn(['editor', 'indentSize'], 2) return ( + +
{'User tab character'}
+
+ {'Tab size:'} + { + e.preventDefault() + e.stopPropagation() + }} + onChange={e => this.changeEditorSetting('tabSize')(Number(e.target.value))} + /> +
+
+
+ {'Indent size:'} + { + e.preventDefault() + e.stopPropagation() + }} + onChange={e => this.changeEditorSetting('indentSize')(Number(e.target.value))} + /> +