From 1cad4fc8eafdc0dacd895f00aee9146233adbaf0 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 14 Oct 2016 13:46:15 +0200 Subject: [PATCH] Implemented `onChangeText` --- src/CodeMode.js | 8 +++++--- src/TextMode.js | 6 +++++- src/develop.html | 3 +++ src/typedef.js | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/CodeMode.js b/src/CodeMode.js index 02981d6..371530a 100644 --- a/src/CodeMode.js +++ b/src/CodeMode.js @@ -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() + } } /** diff --git a/src/TextMode.js b/src/TextMode.js index 7aa165d..68cefdc 100644 --- a/src/TextMode.js +++ b/src/TextMode.js @@ -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 */ diff --git a/src/develop.html b/src/develop.html index 3d93dde..fca0ccc 100644 --- a/src/develop.html +++ b/src/develop.html @@ -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 diff --git a/src/typedef.js b/src/typedef.js index f326010..51efbd5 100644 --- a/src/typedef.js +++ b/src/typedef.js @@ -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 *