Skip to content

Commit a75e17f

Browse files
committed
feat: show no results page when no results match in find in files
1 parent e4d5495 commit a75e17f

3 files changed

Lines changed: 67 additions & 11 deletions

File tree

src/search/FindInFilesUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ define(function (require, exports, module) {
111111
}
112112

113113
} else {
114-
_resultsView.close();
114+
_resultsView.showNoResults();
115115

116116
if (_findBar) {
117117
var showMessage = false;

src/search/SearchResultsView.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ define(function (require, exports, module) {
9797
}).observe(this._panel.$panel[0]);
9898

9999
function _showPanelIfResultsAvailable(_e, shownPanelID) {
100-
if(self._model.numMatches === 0){
101-
self._panel.hide();
102-
}
103-
if(shownPanelID === self._panel.panelID && !self._model.isReplace){
104-
// If it is replace, _handleModelChange will close the find bar as we dont
105-
// do replace if there is a model change. So we wont enter this flow if it is a replace operation
100+
if (shownPanelID === self._panel.panelID && self._model.numMatches > 0 && !self._model.isReplace) {
101+
// Refresh results when the tab is re-activated (they may have changed
102+
// while the panel was in a background tab). Skip when numMatches is 0
103+
// so the "no results" state isn't disturbed.
106104
self._handleModelChange();
107105
}
108106
}
@@ -525,18 +523,18 @@ define(function (require, exports, module) {
525523
let self = this;
526524
let count = self._model.countFilesMatches(),
527525
lastIndex = self._getLastIndex(count.matches),
528-
typeStr = (count.matches > 1) ? Strings.FIND_IN_FILES_MATCHES : Strings.FIND_IN_FILES_MATCH,
526+
typeStr = (count.matches !== 1) ? Strings.FIND_IN_FILES_MATCHES : Strings.FIND_IN_FILES_MATCH,
529527
filesStr,
530528
summary;
531529

532530
if(this._searchResultsType === "reference") {
533-
typeStr = (count.matches > 1) ? Strings.REFERENCES_IN_FILES : Strings.REFERENCE_IN_FILES;
531+
typeStr = (count.matches !== 1) ? Strings.REFERENCES_IN_FILES : Strings.REFERENCE_IN_FILES;
534532
}
535533

536534
filesStr = StringUtils.format(
537535
Strings.FIND_NUM_FILES,
538536
count.files,
539-
(count.files > 1 ? Strings.FIND_IN_FILES_FILES : Strings.FIND_IN_FILES_FILE)
537+
(count.files !== 1 ? Strings.FIND_IN_FILES_FILES : Strings.FIND_IN_FILES_FILE)
540538
);
541539

542540
// This text contains some formatting, so all the strings are assumed to be already escaped
@@ -571,8 +569,15 @@ define(function (require, exports, module) {
571569
* Shows the current set of results.
572570
*/
573571
SearchResultsView.prototype._render = function () {
572+
let count = this._model.countFilesMatches();
573+
if (count.matches === 0) {
574+
this.showNoResults();
575+
return;
576+
}
577+
578+
this._panel.$panel.removeClass("search-no-results");
579+
574580
let searchItems, match, i, item, multiLine,
575-
count = this._model.countFilesMatches(),
576581
searchFiles = this._model.prioritizeOpenFile(this._initialFilePath),
577582
lastIndex = this._getLastIndex(count.matches),
578583
matchesCounter = 0,
@@ -818,12 +823,38 @@ define(function (require, exports, module) {
818823
this._model.on("change.SearchResultsView", this._handleModelChange.bind(this));
819824
};
820825

826+
/**
827+
* Opens the panel and displays a "no results" message instead of closing it.
828+
* Keeps the tab visible so the user gets clear feedback without jarring tab switches.
829+
* @param {string=} message Optional message to display. Defaults to Strings.FIND_NO_RESULTS.
830+
*/
831+
SearchResultsView.prototype.showNoResults = function (message) {
832+
this._currentStart = 0;
833+
this._$selectedRow = null;
834+
this._allChecked = false;
835+
836+
this._$table.empty();
837+
this._closePreviewEditor();
838+
839+
this._panel.$panel.addClass("search-no-results");
840+
this._showSummary();
841+
this._$table.append(
842+
$('<div class="search-no-results-message"></div>').text(message || Strings.FIND_NO_RESULTS)
843+
);
844+
845+
this._panel.$panel.off(".searchResults");
846+
this._model.off("change.SearchResultsView");
847+
848+
this._panel.show();
849+
};
850+
821851
/**
822852
* Hides the Search Results Panel and unregisters listeners.
823853
*/
824854
SearchResultsView.prototype.close = function () {
825855
if (this._panel && this._panel.isVisible()) {
826856
this._$table.empty();
857+
this._panel.$panel.removeClass("search-no-results");
827858
this._panel.hide();
828859
this._panel.$panel.off(".searchResults");
829860
this._model.off("change.SearchResultsView");

src/styles/brackets.less

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,31 @@ a, img {
19811981
}
19821982
}
19831983

1984+
.search-results.search-no-results {
1985+
.table-container {
1986+
width: 100% !important;
1987+
}
1988+
.search-editor-preview {
1989+
display: none !important;
1990+
}
1991+
}
1992+
1993+
.search-no-results-message {
1994+
display: flex;
1995+
align-items: center;
1996+
justify-content: center;
1997+
height: 100%;
1998+
color: #888;
1999+
font-size: 15px;
2000+
letter-spacing: 0.5px;
2001+
word-spacing: 1px;
2002+
user-select: none;
2003+
2004+
.dark & {
2005+
color: #999;
2006+
}
2007+
}
2008+
19842009
.search-results .disclosure-triangle,
19852010
#problems-panel .disclosure-triangle {
19862011
.expand-collapse-triangle();

0 commit comments

Comments
 (0)