Implemented `onChangeText`

This commit is contained in:
jos 2016-10-14 13:46:15 +02:00
parent 5ff41f2d9d
commit 1cad4fc8ea
4 changed files with 15 additions and 4 deletions

View File

@ -66,7 +66,7 @@ export default class CodeMode extends TextMode {
aceEditor.setShowPrintMargin(false)
aceEditor.setFontSize(13)
aceEditor.getSession().setMode('ace/mode/json')
aceEditor.getSession().setTabSize(options.indentation)
aceEditor.getSession().setTabSize(options.indentation || 2)
aceEditor.getSession().setUseSoftTabs(true)
aceEditor.getSession().setUseWrapMode(true)
aceEditor.commands.bindKey('Ctrl-L', null) // disable Ctrl+L (is used by the browser to select the address bar)
@ -105,8 +105,10 @@ export default class CodeMode extends TextMode {
}
handleChange = () => {
// TODO: handle changes
// console.log('ace editor changed')
if (this.props.options && this.props.options.onChangeText) {
// TODO: pass a diff
this.props.options.onChangeText()
}
}
/**

View File

@ -44,7 +44,7 @@ export default class TextMode extends Component {
h('textarea', {
class: 'jsoneditor-text',
value: this.state.text,
onChange: this.handleChange
onInput: this.handleChange
})
])
])
@ -93,6 +93,10 @@ export default class TextMode extends Component {
*/
handleChange = (event) => {
this.setText(event.target.value)
if (this.props.options && this.props.options.onChangeText) {
this.props.options.onChangeText()
}
}
/** @protected */

View File

@ -39,6 +39,9 @@
window.patch = patch
window.revert = revert
},
onChangeText: function () {
console.log('onChangeText')
},
onChangeMode: function (mode, prevMode) {
console.log('switched mode from', prevMode, 'to', mode)
document.getElementById('mode').value = mode

View File

@ -35,6 +35,8 @@
* modes: string[],
* indentation: number | string,
* onChange: function (patch: JSONPatch, revert: JSONPatch),
* onChangeText: function (),
* onChangeMode: function (mode: string, prevMode: string),
* onError: function (err: Error)
* }} Options
*