Fixed #38: clear search results after a new JSON object is set

This commit is contained in:
jos 2015-12-25 10:45:28 +01:00
parent cafd4daba3
commit 75994c8035
3 changed files with 21 additions and 9 deletions

View File

@ -8,12 +8,13 @@ https://github.com/josdejong/jsoneditor
- Replaced the PNG icon images with SVG. Thanks @1j01.
- Implemented a new option `escapeUnicode`, which will show the hexadecimal
unicode instead of the character itself. (See #93 and #230).
- Fixed #227: html codes like `&` not escaped.
- Fixed #93 and #227: html codes like `&` not escaped.
- Fixed #149: Memory leak when switching mode from/to `code` mode, web worker
of Ace editor wasn't cleaned up.
- Fixed #234: Remove dependency on a fork of the `jsonlint` project on github.
- Fixed: disabled `Ctrl+L` quick key to go to a line, instead use the default
browser behavior of selecting the address bar.
- Fixed #38: clear search results after a new JSON object is set.
## 2015-06-13, version 4.2.1

View File

@ -61,7 +61,7 @@ function SearchBox (editor, container) {
searchBox._onDelayedSearch(event);
};
search.onchange = function (event) { // For IE 9
searchBox._onSearch(event);
searchBox._onSearch();
};
search.onkeydown = function (event) {
searchBox._onKeyDown(event);
@ -203,20 +203,19 @@ SearchBox.prototype._onDelayedSearch = function (event) {
this._clearDelay();
var searchBox = this;
this.timeout = setTimeout(function (event) {
searchBox._onSearch(event);
},
this.delay);
searchBox._onSearch();
},
this.delay);
};
/**
* Handle onSearch event
* @param {Event} event
* @param {boolean} [forceSearch] If true, search will be executed again even
* when the search text is not changed.
* Default is false.
* @private
*/
SearchBox.prototype._onSearch = function (event, forceSearch) {
SearchBox.prototype._onSearch = function (forceSearch) {
this._clearDelay();
var value = this.dom.search.value;
@ -251,14 +250,14 @@ SearchBox.prototype._onKeyDown = function (event) {
var keynum = event.which;
if (keynum == 27) { // ESC
this.dom.search.value = ''; // clear search
this._onSearch(event);
this._onSearch();
event.preventDefault();
event.stopPropagation();
}
else if (keynum == 13) { // Enter
if (event.ctrlKey) {
// force to search again
this._onSearch(event, true);
this._onSearch(true);
}
else if (event.shiftKey) {
// move to the previous search result
@ -285,4 +284,13 @@ SearchBox.prototype._onKeyUp = function (event) {
}
};
/**
* Set search text. Will apply a new search
* @param {string} value
*/
SearchBox.prototype.setValue = function (value) {
this.dom.search.value = value;
this._onSearch();
};
module.exports = SearchBox;

View File

@ -126,6 +126,9 @@ treemode.set = function (json, name) {
if (this.history) {
this.history.clear();
}
// clear search
this.searchBox.setValue('');
};
/**