Prefix with ! can search crates exclusively

This commit is contained in:
Folyd 2019-11-20 18:29:08 +08:00
parent 58f8e64cf6
commit 60f63681bb
2 changed files with 6 additions and 5 deletions

View file

@ -62,7 +62,7 @@ function CrateSearch(crateIndex) {
* @returns
*/
CrateSearch.prototype.search = function(keyword, limit = 10) {
keyword = keyword.replace(/[-_\s]/ig, "");
keyword = keyword.replace(/[-_\s!]/ig, "");
let result = [];
for (let rawCrateId of this.crateIds) {
let crateId = rawCrateId.replace(/[-_\s]/ig, "");

View file

@ -20,11 +20,12 @@ Omnibox.prototype.bootstrap = function() {
this.browser.omnibox.onInputChanged.addListener((query, suggestFn) => {
if (!query) return;
const searchResults = window.search(query);
this.suggestResults = [];
for (let result of searchResults) {
this.appendSuggestResult(result);
if (!query.startsWith("!")) {
const searchResults = window.search(query);
for (let result of searchResults) {
this.appendSuggestResult(result);
}
}
if (this.suggestResults.length < 5 && /e\d{2,4}$/ig.test(query)) {