Fixed #294: Fields reset their caret location on every key press in Firefox

This commit is contained in:
jos 2016-04-18 20:41:07 +02:00
parent 0557db02f2
commit e8092db9b4
2 changed files with 52 additions and 34 deletions

View File

@ -3,6 +3,11 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet released, version 5.5.2
- Fixed #294: Fields reset their caret location on every key press in Firefox.
## 2016-04-16, version 5.5.1 ## 2016-04-16, version 5.5.1
- Fixed enum select boxes not being rendered/removed when setting or removing - Fixed enum select boxes not being rendered/removed when setting or removing

View File

@ -1915,48 +1915,22 @@ Node.prototype.updateDom = function (options) {
domField.className = 'jsoneditor-readonly'; domField.className = 'jsoneditor-readonly';
} }
var field; var fieldText;
if (this.index != undefined) { if (this.index != undefined) {
field = this.index; fieldText = this.index;
} }
else if (this.field != undefined) { else if (this.field != undefined) {
field = this.field; fieldText = this.field;
} }
else if (this._hasChilds()) { else if (this._hasChilds()) {
field = this.type; fieldText = this.type;
} }
else { else {
field = ''; fieldText = '';
} }
domField.innerHTML = this._escapeHTML(field); domField.innerHTML = this._escapeHTML(fieldText);
}
//Locating the schema of the node and checking for any enum type this._updateSchema();
if(this.editor && this.editor.options) {
//Search for the schema element of the current node and store it in the schema attribute.
//Hereafter, wherever you have access in the node you will have also access in its own schema.
this.schema = this._getJsonObject(this.editor.options.schema, 'name', field)[0];
if(!this.schema) {
this.schema = this._getJsonObject(this.editor.options.schema, field)[0];
}
//Search for any enumeration type in the schema of the current node.
//Enum types can be also be part of a composite type.
if(this.schema){
if(this.schema.hasOwnProperty('enum')){
this.enum = new Object();
this.enum.enum = this.schema.enum;
} else if(this.schema.hasOwnProperty('oneOf')){
this.enum = this._getJsonObject(this.schema.oneOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('anyOf')){
this.enum = this._getJsonObject(this.schema.anyOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('allOf')){
this.enum = this._getJsonObject(this.schema.allOf, 'enum')[0];
} else {
delete this.enum;
}
} else {
delete this.enum;
}
} }
// apply value to DOM // apply value to DOM
@ -2002,6 +1976,43 @@ Node.prototype.updateDom = function (options) {
} }
}; };
/**
* Locate the JSON schema of the node and check for any enum type
* @private
*/
Node.prototype._updateSchema = function () {
//Locating the schema of the node and checking for any enum type
if(this.editor && this.editor.options) {
var field = (this.index != undefined) ? this.index : this.field;
//Search for the schema element of the current node and store it in the schema attribute.
//Hereafter, wherever you have access in the node you will have also access in its own schema.
this.schema = this._getJsonObject(this.editor.options.schema, 'name', field)[0];
if(!this.schema) {
this.schema = this._getJsonObject(this.editor.options.schema, field)[0];
}
//Search for any enumeration type in the schema of the current node.
//Enum types can be also be part of a composite type.
if(this.schema){
if(this.schema.hasOwnProperty('enum')){
this.enum = {};
this.enum.enum = this.schema.enum;
} else if(this.schema.hasOwnProperty('oneOf')){
this.enum = this._getJsonObject(this.schema.oneOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('anyOf')){
this.enum = this._getJsonObject(this.schema.anyOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('allOf')){
this.enum = this._getJsonObject(this.schema.allOf, 'enum')[0];
} else {
delete this.enum;
}
} else {
delete this.enum;
}
}
};
/** /**
* Get all sub-elements of the given object with the specified key and value. * Get all sub-elements of the given object with the specified key and value.
* @private * @private
@ -2293,7 +2304,9 @@ Node.prototype.onEvent = function (event) {
case 'input': case 'input':
this._getDomField(true); this._getDomField(true);
this.updateDom(); this._updateSchema();
this._updateDomField();
this._updateDomValue();
break; break;
case 'keydown': case 'keydown':