Skip to content

Commit

Permalink
Merge pull request #232 from Odrin/feature/editor-indent-settings
Browse files Browse the repository at this point in the history
Move CodeMirror indent settings to app settings
  • Loading branch information
meriadec authored Mar 28, 2018
2 parents c10d5b0 + 8e4e6e5 commit 2668035
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist/
node_modules/
thumbs.db
/.idea
3 changes: 3 additions & 0 deletions src/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export function loadSettings() {
foldLevel: 1,
highlightTag: false,
lightTheme: false,
useTab: false,
tabSize: 2,
indentSize: 2,
},
mjml: {
minify: false,
Expand Down
27 changes: 23 additions & 4 deletions src/components/FileEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
},
{
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -170,19 +182,26 @@ 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()
this._codeMirror = null
}

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',
Expand Down
36 changes: 36 additions & 0 deletions src/components/SettingsModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Modal
Expand Down Expand Up @@ -156,6 +159,39 @@ class SettingsModal extends Component {
/>
</div>
</CheckBox>
<CheckBox value={editorUseTab} onChange={this.changeEditorSetting('useTab')}>
<div>{'User tab character'}</div>
<div className="mt-5">
{'Tab size:'}
<input
className="ml-5"
type="number"
min={1}
style={{ width: 80 }}
value={editorTabSize}
onClick={e => {
e.preventDefault()
e.stopPropagation()
}}
onChange={e => this.changeEditorSetting('tabSize')(Number(e.target.value))}
/>
</div>
</CheckBox>
<div className="mt-5">
{'Indent size:'}
<input
className="ml-5"
type="number"
min={1}
style={{ width: 80 }}
value={editorIndentSize}
onClick={e => {
e.preventDefault()
e.stopPropagation()
}}
onChange={e => this.changeEditorSetting('indentSize')(Number(e.target.value))}
/>
</div>
</TabItem>

<TabItem title="Preview" className="flow-v-10" icon={IconPreview}>
Expand Down

0 comments on commit 2668035

Please sign in to comment.