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

Addressed review comments and also added tests

This commit is contained in:
Saurabh Kathpalia 2017-03-28 15:00:27 +05:30
parent a70549e783
commit b99b4ddb22
2 changed files with 49 additions and 11 deletions

View File

@ -267,7 +267,7 @@ define(function (require, exports, module) {
FindBar._addFindBar(this);
var $root = this._modalBar.getRoot();
var currentIndex = 0;
var historyIndex = 0;
$root
.on("input", "#find-what", function () {
self.trigger("queryChange");
@ -321,7 +321,7 @@ define(function (require, exports, module) {
searchHistory.splice(searchQueryIndex, 1);
} else {
if (searchHistory.length === maxCount) {
searchHistory.splice(maxCount - 1, 1);
searchHistory.pop();
}
}
searchHistory.unshift($('#find-what').val());
@ -346,14 +346,14 @@ define(function (require, exports, module) {
// if Shift is held down).
self.trigger("doFind", e.shiftKey);
}
currentIndex = 0;
} else if (e.keyCode === KeyEvent.DOM_VK_DOWN) {
currentIndex = (currentIndex - 1 + Math.min(maxCount, searchHistory.length)) % Math.min(maxCount, searchHistory.length);
$("#find-what").val(searchHistory[currentIndex]);
self.trigger("queryChange");
} else if (e.keyCode === KeyEvent.DOM_VK_UP) {
currentIndex = (currentIndex + 1 + Math.min(maxCount, searchHistory.length)) % Math.min(maxCount, searchHistory.length);
$("#find-what").val(searchHistory[currentIndex]);
historyIndex = 0;
} else if (e.keyCode === KeyEvent.DOM_VK_DOWN || e.keyCode === KeyEvent.DOM_VK_UP) {
if (e.keyCode === KeyEvent.DOM_VK_DOWN) {
historyIndex = (historyIndex - 1 + searchHistory.length) % searchHistory.length;
} else {
historyIndex = (historyIndex + 1 + searchHistory.length) % searchHistory.length;
}
$("#find-what").val(searchHistory[historyIndex]);
self.trigger("queryChange");
}
});
@ -639,7 +639,7 @@ define(function (require, exports, module) {
PreferencesManager.stateManager.definePreference("caseSensitive", "boolean", false);
PreferencesManager.stateManager.definePreference("regexp", "boolean", false);
PreferencesManager.stateManager.definePreference("searchHistory", "array", []);
PreferencesManager.definePreference("maxSearchHistory", "number", 10, {
PreferencesManager.definePreference("maxSearchHistory", "number", 10, {
description: Strings.FIND_HISTORY_MAX_COUNT
});

View File

@ -86,6 +86,7 @@ define(function (require, exports, module) {
PreferencesManager = testWindow.brackets.test.PreferencesManager;
PreferencesManager.set("findInFiles.nodeSearch", false);
PreferencesManager.set("findInFiles.instantSearch", false);
PreferencesManager.set("maxSearchHistory", 5);
});
});
@ -409,6 +410,43 @@ define(function (require, exports, module) {
expect(fileResults).toBeFalsy();
});
});
it("should verify the contents of searchHistory array", function () {
var fileEntry = FileSystem.getFileForPath(testPath + "/foo.js");
openSearchBar(fileEntry);
executeSearch("foo1");
executeSearch("foo2");
executeSearch("foo3");
executeSearch("foo4");
executeSearch("foo5");
runs(function () {
var searchHistory = PreferencesManager.getViewState("searchHistory");
expect(searchHistory.length).toBe(5);
expect(searchHistory).toEqual(["foo5", "foo4", "foo3", "foo2", "foo1"]);
});
});
it("should traverse through search history using up and down arrow keys", function () {
var fileEntry = FileSystem.getFileForPath(testPath + "/foo.js");
openSearchBar(fileEntry);
executeSearch("foo1");
executeSearch("foo2");
executeSearch("foo3");
executeSearch("foo4");
executeSearch("foo5");
runs(function () {
var searchHistory = PreferencesManager.getViewState("searchHistory");
var $searchField = $("#find-what");
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_UP, "keydown", $searchField[0]);
expect($("#find-what").val()).toBe("foo4");
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_DOWN, "keydown", $searchField[0]);
expect($("#find-what").val()).toBe("foo5");
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_DOWN, "keydown", $searchField[0]);
expect($("#find-what").val()).toBe("foo1");
});
});
it("should find start and end positions", function () {
var filePath = testPath + "/foo.js",