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

Commit b4c1c48

Browse files
committed
Merge pull request #3184 from adobe/dangoor/2608-quickopen-red
Fixes #2608 (Quick Open shows red on first use)
2 parents 5fdee03 + f419483 commit b4c1c48

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

src/search/QuickOpen.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ define(function (require, exports, module) {
400400
* list items are re-rendered. Both happen synchronously just after we return. Called even when results is empty.
401401
*/
402402
QuickNavigateDialog.prototype._handleResultsReady = function (e, results) {
403-
// Give visual clue when there are no results
404-
var isNoResults = (results.length === 0 && !this._isValidLineNumberQuery(this.$searchField.val()));
405-
this.$searchField.toggleClass("no-results", isNoResults);
403+
// Give visual clue when there are no results (unless we're in "Go To Line" mode, where there
404+
// are never results, or we're in file search mode and waiting for the index to get rebuilt)
405+
var isNoResults = (results.length === 0 && (fileList || currentPlugin) && !this._isValidLineNumberQuery(this.$searchField.val()));
406+
this.$searchField.toggleClass("no-results", Boolean(isNoResults));
406407
};
407408

408409
/**
@@ -787,12 +788,12 @@ define(function (require, exports, module) {
787788

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

798799
function getCurrentEditorSelectedText() {
@@ -834,8 +835,11 @@ define(function (require, exports, module) {
834835
beginSearch("@", getCurrentEditorSelectedText());
835836
}
836837
}
837-
838-
838+
839+
// Listen for a change of project to invalidate our file list
840+
$(ProjectManager).on("projectOpen", function () {
841+
fileList = null;
842+
});
839843

840844
// TODO: allow QuickOpenJS to register it's own commands and key bindings
841845
CommandManager.register(Strings.CMD_QUICK_OPEN, Commands.NAVIGATE_QUICK_OPEN, doFileSearch);

src/utils/StringMatch.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,7 @@ define(function (require, exports, module) {
761761
* (This object's caches are all stored in "_" prefixed properties.)
762762
*/
763763
function StringMatcher() {
764-
// We keep track of the last query to know when we need to invalidate.
765-
this._lastQuery = null;
766-
767-
this._specialsCache = {};
768-
this._noMatchCache = {};
764+
this.reset();
769765
}
770766

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

781+
/**
782+
* Clears the caches. Use this in the event that the caches may be invalid.
783+
*/
784+
StringMatcher.prototype.reset = function () {
785+
// We keep track of the last query to know when we need to invalidate.
786+
this._lastQuery = null;
787+
788+
this._specialsCache = {};
789+
this._noMatchCache = {};
790+
};
791+
785792
/**
786793
* Performs a single match using the stringMatch function. See stringMatch for full documentation.
787794
*

test/spec/StringMatch-test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ define(function (require, exports, module) {
594594
});
595595

596596
describe("StringMatcher", function () {
597-
it("should manage its caches properly", function () {
597+
beforeEach(function () {
598598
this.addMatchers({
599599
toBeInCache: function (matcher, cacheName) {
600600
var value = matcher[cacheName][this.actual];
@@ -607,7 +607,9 @@ define(function (require, exports, module) {
607607
return value !== undefined;
608608
}
609609
});
610-
610+
});
611+
612+
it("should manage its caches properly", function () {
611613
var matcher = new StringMatch.StringMatcher();
612614
expect(matcher._noMatchCache).toEqual({});
613615
expect(matcher._specialsCache).toEqual({});
@@ -646,6 +648,16 @@ define(function (require, exports, module) {
646648
var hasOwnPropertyResult = matcher.match("hasOwnProperty", "h");
647649
expect(hasOwnPropertyResult).toBeTruthy();
648650
});
651+
652+
it("can reset the caches", function () {
653+
var matcher = new StringMatch.StringMatcher();
654+
matcher.match("foo", "spec/live");
655+
expect("foo").toBeInCache(matcher, "_specialsCache");
656+
expect("foo").toBeInCache(matcher, "_noMatchCache");
657+
matcher.reset();
658+
expect("foo").not.toBeInCache(matcher, "_specialsCache");
659+
expect("foo").not.toBeInCache(matcher, "_noMatchCache");
660+
});
649661
});
650662
});
651663
});

0 commit comments

Comments
 (0)