mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-15 08:07:08 +00:00
Prefix with ! can search crates exclusively
This commit is contained in:
parent
58f8e64cf6
commit
60f63681bb
2 changed files with 6 additions and 5 deletions
|
@ -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, "");
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue