1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

CodeEditor can handle 'code:format-table' event

This commit is contained in:
amedora
2018-06-28 13:33:48 +09:00
parent f0941f47dd
commit 7bacd6f8f0

View File

@@ -50,6 +50,8 @@ export default class CodeEditor extends React.Component {
} }
this.searchHandler = (e, msg) => this.handleSearch(msg) this.searchHandler = (e, msg) => this.handleSearch(msg)
this.searchState = null this.searchState = null
this.formatTable = () => this.handleFormatTable()
} }
handleSearch (msg) { handleSearch (msg) {
@@ -83,6 +85,10 @@ export default class CodeEditor extends React.Component {
}) })
} }
handleFormatTable () {
this.tableEditor.formatAll(options({textWidthOptions: {}}))
}
componentDidMount () { componentDidMount () {
const { rulers, enableRulers } = this.props const { rulers, enableRulers } = this.props
const expandSnippet = this.expandSnippet.bind(this) const expandSnippet = this.expandSnippet.bind(this)
@@ -186,6 +192,7 @@ export default class CodeEditor extends React.Component {
CodeMirror.Vim.map('ZZ', ':q', 'normal') CodeMirror.Vim.map('ZZ', ':q', 'normal')
this.tableEditor = new TableEditor(new TextEditorInterface(this.editor)) this.tableEditor = new TableEditor(new TextEditorInterface(this.editor))
eventEmitter.on('code:format-table', this.formatTable)
} }
expandSnippet (line, cursor, cm, snippets) { expandSnippet (line, cursor, cm, snippets) {
@@ -268,6 +275,8 @@ export default class CodeEditor extends React.Component {
this.editor.off('scroll', this.scrollHandler) this.editor.off('scroll', this.scrollHandler)
const editorTheme = document.getElementById('editorTheme') const editorTheme = document.getElementById('editorTheme')
editorTheme.removeEventListener('load', this.loadStyleHandler) editorTheme.removeEventListener('load', this.loadStyleHandler)
eventEmitter.off('code:format-table', this.formatTable)
} }
componentDidUpdate (prevProps, prevState) { componentDidUpdate (prevProps, prevState) {