From 75994c8035f9722730dd25fb1ea6a676bdf252cf Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 25 Dec 2015 10:45:28 +0100 Subject: [PATCH] Fixed #38: clear search results after a new JSON object is set --- HISTORY.md | 3 ++- src/js/SearchBox.js | 24 ++++++++++++++++-------- src/js/treemode.js | 3 +++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 391a1cc..ea902dc 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/src/js/SearchBox.js b/src/js/SearchBox.js index e9c2b23..f8b1f02 100644 --- a/src/js/SearchBox.js +++ b/src/js/SearchBox.js @@ -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; diff --git a/src/js/treemode.js b/src/js/treemode.js index c58f5ac..75888f6 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -126,6 +126,9 @@ treemode.set = function (json, name) { if (this.history) { this.history.clear(); } + + // clear search + this.searchBox.setValue(''); }; /**