diff --git a/src/js/JSONEditor.js b/src/js/JSONEditor.js index 8e5b6be..842fa69 100644 --- a/src/js/JSONEditor.js +++ b/src/js/JSONEditor.js @@ -44,6 +44,14 @@ var util = require('./util'); * {boolean} sortObjectKeys If true, object keys are * sorted before display. * false by default. + * {function} onNodeSelectionChange Callback method, + * triggered on node selection change + * Only applicable for modes + * 'tree', 'view', and 'form' + * {function} onTextSelectionChange Callback method, + * triggered on text selection change + * Only applicable for modes + * 'text' and 'code' * @param {Object | undefined} json JSON object */ function JSONEditor (container, options, json) { @@ -81,7 +89,7 @@ function JSONEditor (container, options, json) { var VALID_OPTIONS = [ 'ajv', 'schema', 'schemaRefs','templates', 'ace', 'theme','autocomplete', - 'onChange', 'onEditable', 'onError', 'onModeChange', + 'onChange', 'onEditable', 'onError', 'onModeChange', 'onNodeSelectionChange', 'onTextSelectionChange', 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys', 'navigationBar', 'statusBar' ]; diff --git a/src/js/textmode.js b/src/js/textmode.js index 2c8d0da..b27e3d7 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -31,6 +31,8 @@ var DEFAULT_THEME = 'ace/theme/jsoneditor'; * {boolean} escapeUnicode If true, unicode * characters are escaped. * false by default. + * {function} onTextSelectionChange Callback method, + * triggered on text selection change * @private */ textmode.create = function (container, options) { @@ -76,6 +78,10 @@ textmode.create = function (container, options) { } } + if (options.onTextSelectionChange) { + this.onTextSelectionChange(options.onTextSelectionChange); + } + var me = this; this.container = container; this.dom = {}; @@ -699,7 +705,7 @@ textmode.getTextSelection = function () { * @param {{row:Number, column:Number}} startPos selection start position * @param {{row:Number, column:Number}} endPos selected end position */ -textmode.onTextSelectionChanged = function (callback) { +textmode.onTextSelectionChange = function (callback) { if (typeof callback === 'function') { this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL); } diff --git a/src/js/treemode.js b/src/js/treemode.js index 26fe5d2..dd01892 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -115,7 +115,8 @@ treemode._setOptions = function (options) { schema: null, schemaRefs: null, autocomplete: null, - navigationBar : true + navigationBar : true, + onNodeSelectionChange: null }; // copy all options @@ -132,6 +133,10 @@ treemode._setOptions = function (options) { // create a debounced validate function this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL); + + if (options.onNodeSelectionChange) { + this.onNodeSelectionChange(options.onNodeSelectionChange); + } }; /** @@ -1349,7 +1354,7 @@ treemode.getNodeSelection = function () { * @callback selectionCallback * @param {Array} nodes selected nodes */ -treemode.onNodeSelectionChanged = function (callback) { +treemode.onNodeSelectionChange = function (callback) { if (typeof callback === 'function') { this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL); }