add on{Text/Node}SelectionChange configurations to editor options
This commit is contained in:
parent
f04eff7b4e
commit
55674f5b0f
|
@ -44,6 +44,14 @@ var util = require('./util');
|
||||||
* {boolean} sortObjectKeys If true, object keys are
|
* {boolean} sortObjectKeys If true, object keys are
|
||||||
* sorted before display.
|
* sorted before display.
|
||||||
* false by default.
|
* 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
|
* @param {Object | undefined} json JSON object
|
||||||
*/
|
*/
|
||||||
function JSONEditor (container, options, json) {
|
function JSONEditor (container, options, json) {
|
||||||
|
@ -81,7 +89,7 @@ function JSONEditor (container, options, json) {
|
||||||
var VALID_OPTIONS = [
|
var VALID_OPTIONS = [
|
||||||
'ajv', 'schema', 'schemaRefs','templates',
|
'ajv', 'schema', 'schemaRefs','templates',
|
||||||
'ace', 'theme','autocomplete',
|
'ace', 'theme','autocomplete',
|
||||||
'onChange', 'onEditable', 'onError', 'onModeChange',
|
'onChange', 'onEditable', 'onError', 'onModeChange', 'onNodeSelectionChange', 'onTextSelectionChange',
|
||||||
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
|
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
|
||||||
'sortObjectKeys', 'navigationBar', 'statusBar'
|
'sortObjectKeys', 'navigationBar', 'statusBar'
|
||||||
];
|
];
|
||||||
|
|
|
@ -31,6 +31,8 @@ var DEFAULT_THEME = 'ace/theme/jsoneditor';
|
||||||
* {boolean} escapeUnicode If true, unicode
|
* {boolean} escapeUnicode If true, unicode
|
||||||
* characters are escaped.
|
* characters are escaped.
|
||||||
* false by default.
|
* false by default.
|
||||||
|
* {function} onTextSelectionChange Callback method,
|
||||||
|
* triggered on text selection change
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode.create = function (container, options) {
|
textmode.create = function (container, options) {
|
||||||
|
@ -76,6 +78,10 @@ textmode.create = function (container, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.onTextSelectionChange) {
|
||||||
|
this.onTextSelectionChange(options.onTextSelectionChange);
|
||||||
|
}
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.dom = {};
|
this.dom = {};
|
||||||
|
@ -699,7 +705,7 @@ textmode.getTextSelection = function () {
|
||||||
* @param {{row:Number, column:Number}} startPos selection start position
|
* @param {{row:Number, column:Number}} startPos selection start position
|
||||||
* @param {{row:Number, column:Number}} endPos selected end position
|
* @param {{row:Number, column:Number}} endPos selected end position
|
||||||
*/
|
*/
|
||||||
textmode.onTextSelectionChanged = function (callback) {
|
textmode.onTextSelectionChange = function (callback) {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL);
|
this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,8 @@ treemode._setOptions = function (options) {
|
||||||
schema: null,
|
schema: null,
|
||||||
schemaRefs: null,
|
schemaRefs: null,
|
||||||
autocomplete: null,
|
autocomplete: null,
|
||||||
navigationBar : true
|
navigationBar : true,
|
||||||
|
onNodeSelectionChange: null
|
||||||
};
|
};
|
||||||
|
|
||||||
// copy all options
|
// copy all options
|
||||||
|
@ -132,6 +133,10 @@ treemode._setOptions = function (options) {
|
||||||
|
|
||||||
// create a debounced validate function
|
// create a debounced validate function
|
||||||
this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL);
|
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
|
* @callback selectionCallback
|
||||||
* @param {Array<Node>} nodes selected nodes
|
* @param {Array<Node>} nodes selected nodes
|
||||||
*/
|
*/
|
||||||
treemode.onNodeSelectionChanged = function (callback) {
|
treemode.onNodeSelectionChange = function (callback) {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL);
|
this._selectionChangedHandler = util.debounce(callback, this.DEBOUNCE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue