Skip to content

Commit

Permalink
Better beautify - closes #140
Browse files Browse the repository at this point in the history
  • Loading branch information
meriadec committed Aug 8, 2017
1 parent 9adbffe commit 91034e3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/components/FileEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { connect } from 'react-redux'
import debounce from 'lodash/debounce'
import get from 'lodash/get'
import CodeMirror from 'codemirror'
import beautifyJS from 'js-beautify'

import 'codemirror/addon/selection/active-line'
import 'codemirror/addon/edit/closetag'
Expand Down Expand Up @@ -211,10 +212,14 @@ class FileEditor extends Component {
}, 200)

beautify = () => {
const totalLines = this._codeMirror.lineCount()
const totalChars = this._codeMirror.getTextArea().value.length
this._codeMirror.autoFormatRange({ line: 0, ch: 0 }, { line: totalLines, ch: totalChars })
this._codeMirror.setCursor({ line: 0, ch: 0 })
const value = this._codeMirror.getValue()
const scrollInfo = this._codeMirror.getScrollInfo()
const beautified = beautifyJS.html(value, {
indent_size: 2, // eslint-disable-line camelcase
wrap_attributes_indent_size: 2, // eslint-disable-line camelcase
})
this._codeMirror.setValue(beautified)
this._codeMirror.scrollTo(0, scrollInfo.top)
}

debounceWrite = debounce((fileName, mjml) => {
Expand Down

0 comments on commit 91034e3

Please sign in to comment.