No more expanding of all search results. Search working with large arrays

This commit is contained in:
jos 2018-05-06 21:03:53 +02:00
parent 904110d141
commit 497c20019d
4 changed files with 29 additions and 29 deletions

View File

@ -3,8 +3,13 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet released, version 5.15.1 ## not yet released, version 5.16.0
- Better handling of large JSON documents:
- Only displays the first 100 items of large arrays, with buttons
"show more" and "show all" to render more items.
- Search does no longer expand the paths to all matches, instead
it only expands the path of the current search result.
- Fixed index numbers of Array items not being updated after sorting. - Fixed index numbers of Array items not being updated after sorting.

View File

@ -793,8 +793,7 @@ Node.prototype.insertAfter = function(node, afterNode) {
/** /**
* Search in this node * Search in this node
* The node will be expanded when the text is found one of its childs, else * Searches are case insensitive.
* it will be collapsed. Searches are case insensitive.
* @param {String} text * @param {String} text
* @return {Node[]} results Array with nodes containing the search text * @return {Node[]} results Array with nodes containing the search text
*/ */
@ -808,10 +807,10 @@ Node.prototype.search = function(text) {
delete this.searchValue; delete this.searchValue;
// search in field // search in field
if (this.field != undefined) { if (this.field !== undefined) {
var field = String(this.field).toLowerCase(); var field = String(this.field).toLowerCase();
index = field.indexOf(search); index = field.indexOf(search);
if (index != -1) { if (index !== -1) {
this.searchField = true; this.searchField = true;
results.push({ results.push({
'node': this, 'node': this,
@ -835,24 +834,13 @@ Node.prototype.search = function(text) {
}); });
results = results.concat(childResults); results = results.concat(childResults);
} }
// update dom
if (search != undefined) {
var recurse = false;
if (childResults.length == 0) {
this.collapse(recurse);
}
else {
this.expand(recurse);
}
}
} }
else { else {
// string, auto // string, auto
if (this.value != undefined ) { if (this.value !== undefined ) {
var value = String(this.value).toLowerCase(); var value = String(this.value).toLowerCase();
index = value.indexOf(search); index = value.indexOf(search);
if (index != -1) { if (index !== -1) {
this.searchValue = true; this.searchValue = true;
results.push({ results.push({
'node': this, 'node': this,
@ -874,14 +862,21 @@ Node.prototype.search = function(text) {
* @param {function(boolean)} [callback] * @param {function(boolean)} [callback]
*/ */
Node.prototype.scrollTo = function(callback) { Node.prototype.scrollTo = function(callback) {
if (!this.dom.tr || !this.dom.tr.parentNode) { // if the node is not visible, expand its parents
// if the node is not visible, expand its parents var node = this;
var parent = this.parent; var recurse = false;
var recurse = false; while (node && node.parent) {
while (parent) { // expand max visible childs of the parent if needed
parent.expand(recurse); var index = node.parent.type === 'array'
parent = parent.parent; ? node.index
: node.parent.childs.indexOf(node);
while (node.parent.maxVisibleChilds < index + 1) {
node.parent.maxVisibleChilds += Node.prototype.MAX_VISIBLE_CHILDS;
} }
// expand the parent itself
node.parent.expand(recurse);
node = node.parent;
} }
if (this.dom.tr && this.dom.tr.parentNode) { if (this.dom.tr && this.dom.tr.parentNode) {

View File

@ -226,14 +226,14 @@ SearchBox.prototype._onSearch = function (forceSearch) {
var value = this.dom.search.value; var value = this.dom.search.value;
var text = (value.length > 0) ? value : undefined; var text = (value.length > 0) ? value : undefined;
if (text != this.lastText || forceSearch) { if (text !== this.lastText || forceSearch) {
// only search again when changed // only search again when changed
this.lastText = text; this.lastText = text;
this.results = this.editor.search(text); this.results = this.editor.search(text);
this._setActiveResult(undefined); this._setActiveResult(0, false);
// display search results // display search results
if (text != undefined) { if (text !== undefined) {
var resultCount = this.results.length; var resultCount = this.results.length;
switch (resultCount) { switch (resultCount) {
case 0: this.dom.results.innerHTML = 'no&nbsp;results'; break; case 0: this.dom.results.innerHTML = 'no&nbsp;results'; break;

View File

@ -106,7 +106,7 @@ function showMoreNodeFactory(Node) {
this.dom.moreText.nodeValue = this._getShowMoreText(); this.dom.moreText.nodeValue = this._getShowMoreText();
// update left margin // update left margin
this.dom.moreContents.style.marginLeft = (this.getLevel() + 2) * 24 + 'px'; this.dom.moreContents.style.marginLeft = (this.getLevel() + 1) * 24 + 'px';
} }
else { else {
if (this.dom.tr && this.dom.tr.parentNode) { if (this.dom.tr && this.dom.tr.parentNode) {