1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 18:02:54 +01:00

Merge pull request #13342 from adobe/saurabh95/SearchHistory

Now initial query is also added to searchHistory queue
This commit is contained in:
Martin Zagora 2017-05-05 14:51:06 +10:00 committed by GitHub
commit c8c3adde08
2 changed files with 47 additions and 15 deletions

View File

@ -227,6 +227,28 @@ define(function (require, exports, module) {
$elem.attr("title", oldTitle + "(" + KeyBindingManager.formatKeyDescriptor(replaceShortcut.displayKey) + ")");
}
};
/**
* @private
* Adds element to the search history queue.
* @param {string} search string that needs to be added to history.
*/
FindBar.prototype._addElementToSearchHistory = function (searchVal) {
if (searchVal) {
var searchHistory = PreferencesManager.getViewState("searchHistory");
var maxCount = PreferencesManager.get("maxSearchHistory");
var searchQueryIndex = searchHistory.indexOf(searchVal);
if (searchQueryIndex !== -1) {
searchHistory.splice(searchQueryIndex, 1);
} else {
if (searchHistory.length === maxCount) {
searchHistory.pop();
}
}
searchHistory.unshift(searchVal);
PreferencesManager.setViewState("searchHistory", searchHistory);
}
};
/**
* Opens the Find bar, closing any other existing Find bars.
@ -248,6 +270,8 @@ define(function (require, exports, module) {
templateVars.Strings = Strings;
templateVars.replaceBatchLabel = (templateVars.multifile ? Strings.BUTTON_REPLACE_ALL_IN_FILES : Strings.BUTTON_REPLACE_BATCH);
templateVars.replaceAllLabel = Strings.BUTTON_REPLACE_ALL;
self._addElementToSearchHistory(this._options.initialQuery);
this._modalBar = new ModalBar(Mustache.render(_searchBarTemplate, templateVars), true); // 2nd arg = auto-close on Esc/blur
@ -327,24 +351,10 @@ define(function (require, exports, module) {
if (intervalId === 0) {
intervalId = window.setInterval(executeSearchIfNeeded, 50);
}
var searchHistory = PreferencesManager.getViewState("searchHistory");
var maxCount = PreferencesManager.get("maxSearchHistory");
if (e.keyCode === KeyEvent.DOM_VK_RETURN) {
e.preventDefault();
e.stopPropagation();
var searchVal = self.$("#find-what").val();
var searchQueryIndex = searchHistory.indexOf(searchVal);
if (searchQueryIndex !== -1) {
searchHistory.splice(searchQueryIndex, 1);
} else {
if (searchHistory.length === maxCount) {
searchHistory.pop();
}
}
if (searchVal) {
searchHistory.unshift(searchVal);
}
PreferencesManager.setViewState("searchHistory", searchHistory);
self._addElementToSearchHistory(self.$("#find-what").val());
lastQueriedText = self.getQueryInfo().query;
if (self._options.multifile) {
if ($(e.target).is("#find-what")) {

View File

@ -468,6 +468,28 @@ define(function (require, exports, module) {
expect($("#find-what").val()).toBe("foo1");
});
});
it("should add element to search history if it is pre-filled in search bar", function () {
var fileEntry = FileSystem.getFileForPath(testPath + "/foo.js");
openSearchBar(fileEntry);
runs(function () {
$("#find-what").val("some");
closeSearchBar();
// Adding delay to make sure that search bar is closed
setTimeout(function () {
openSearchBar(fileEntry);
expect($("#find-what").val()).toBe("some");
var searchHistory = PreferencesManager.getViewState("searchHistory");
expect(searchHistory[0]).toBe("some");
var $searchField = $("#find-what");
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_UP, "keydown", $searchField[0]);
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_UP, "keydown", $searchField[0]);
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_RETURN, "keydown", $searchField[0]);
expect($("#find-what").val()).toBe("some");
}, 500);
});
});
it("should find start and end positions", function () {
var filePath = testPath + "/foo.js",