Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3184 from adobe/dangoor/2608-quickopen-red
Browse files Browse the repository at this point in the history
Fixes #2608 (Quick Open shows red on first use)
  • Loading branch information
dangoor committed Apr 4, 2013
2 parents 5fdee03 + f419483 commit b4c1c48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
18 changes: 11 additions & 7 deletions src/search/QuickOpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ define(function (require, exports, module) {
* list items are re-rendered. Both happen synchronously just after we return. Called even when results is empty.
*/
QuickNavigateDialog.prototype._handleResultsReady = function (e, results) {
// Give visual clue when there are no results
var isNoResults = (results.length === 0 && !this._isValidLineNumberQuery(this.$searchField.val()));
this.$searchField.toggleClass("no-results", isNoResults);
// Give visual clue when there are no results (unless we're in "Go To Line" mode, where there
// are never results, or we're in file search mode and waiting for the index to get rebuilt)
var isNoResults = (results.length === 0 && (fileList || currentPlugin) && !this._isValidLineNumberQuery(this.$searchField.val()));
this.$searchField.toggleClass("no-results", Boolean(isNoResults));
};

/**
Expand Down Expand Up @@ -787,12 +788,12 @@ define(function (require, exports, module) {

// Start fetching the file list, which will be needed the first time the user enters an un-prefixed query. If FileIndexManager's
// caches are out of date, this list might take some time to asynchronously build. See searchFileList() for how this is handled.
fileList = null;
fileListPromise = FileIndexManager.getFileInfoList("all")
.done(function (files) {
fileList = files;
fileListPromise = null;
});
this._filenameMatcher.reset();
}.bind(this));
};

function getCurrentEditorSelectedText() {
Expand Down Expand Up @@ -834,8 +835,11 @@ define(function (require, exports, module) {
beginSearch("@", getCurrentEditorSelectedText());
}
}



// Listen for a change of project to invalidate our file list
$(ProjectManager).on("projectOpen", function () {
fileList = null;
});

// TODO: allow QuickOpenJS to register it's own commands and key bindings
CommandManager.register(Strings.CMD_QUICK_OPEN, Commands.NAVIGATE_QUICK_OPEN, doFileSearch);
Expand Down
17 changes: 12 additions & 5 deletions src/utils/StringMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,7 @@ define(function (require, exports, module) {
* (This object's caches are all stored in "_" prefixed properties.)
*/
function StringMatcher() {
// We keep track of the last query to know when we need to invalidate.
this._lastQuery = null;

this._specialsCache = {};
this._noMatchCache = {};
this.reset();
}

/**
Expand All @@ -782,6 +778,17 @@ define(function (require, exports, module) {
*/
StringMatcher.prototype._noMatchCache = null;

/**
* Clears the caches. Use this in the event that the caches may be invalid.
*/
StringMatcher.prototype.reset = function () {
// We keep track of the last query to know when we need to invalidate.
this._lastQuery = null;

this._specialsCache = {};
this._noMatchCache = {};
};

/**
* Performs a single match using the stringMatch function. See stringMatch for full documentation.
*
Expand Down
16 changes: 14 additions & 2 deletions test/spec/StringMatch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ define(function (require, exports, module) {
});

describe("StringMatcher", function () {
it("should manage its caches properly", function () {
beforeEach(function () {
this.addMatchers({
toBeInCache: function (matcher, cacheName) {
var value = matcher[cacheName][this.actual];
Expand All @@ -607,7 +607,9 @@ define(function (require, exports, module) {
return value !== undefined;
}
});

});

it("should manage its caches properly", function () {
var matcher = new StringMatch.StringMatcher();
expect(matcher._noMatchCache).toEqual({});
expect(matcher._specialsCache).toEqual({});
Expand Down Expand Up @@ -646,6 +648,16 @@ define(function (require, exports, module) {
var hasOwnPropertyResult = matcher.match("hasOwnProperty", "h");
expect(hasOwnPropertyResult).toBeTruthy();
});

it("can reset the caches", function () {
var matcher = new StringMatch.StringMatcher();
matcher.match("foo", "spec/live");
expect("foo").toBeInCache(matcher, "_specialsCache");
expect("foo").toBeInCache(matcher, "_noMatchCache");
matcher.reset();
expect("foo").not.toBeInCache(matcher, "_specialsCache");
expect("foo").not.toBeInCache(matcher, "_noMatchCache");
});
});
});
});

0 comments on commit b4c1c48

Please sign in to comment.