mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Add beforeNavigate hook for Omnibox
This commit is contained in:
parent
48fe6e45fa
commit
9a7a541c83
2 changed files with 9 additions and 1 deletions
|
@ -29,6 +29,13 @@ omnibox.bootstrap({
|
|||
description: `Search Rust docs ${c.match(query)} on ${settings.isOfflineMode ? "offline mode" : stdSearcher.rootPath}`,
|
||||
}];
|
||||
},
|
||||
beforeNavigate: (content) => {
|
||||
if (content && content.trim().startsWith("@")) {
|
||||
return `https://docs.rs/${content.replace("@", "")}`;
|
||||
} else {
|
||||
return content;
|
||||
}
|
||||
},
|
||||
onSelected: (query, result) => {
|
||||
HistoryCommand.record(query, result);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ Omnibox.prototype.parse = function(input) {
|
|||
return {query: query.join(" "), page};
|
||||
};
|
||||
|
||||
Omnibox.prototype.bootstrap = function({onSearch, onFormat, onAppend, onSelected}) {
|
||||
Omnibox.prototype.bootstrap = function({onSearch, onFormat, onAppend, beforeNavigate, onSelected}) {
|
||||
this.globalEvent = new QueryEvent({onSearch, onFormat, onAppend});
|
||||
this.setDefaultSuggestion(this.defaultSuggestionDescription);
|
||||
let results;
|
||||
|
@ -80,6 +80,7 @@ Omnibox.prototype.bootstrap = function({onSearch, onFormat, onAppend, onSelected
|
|||
|
||||
chrome.omnibox.onInputEntered.addListener((content, disposition) => {
|
||||
let result;
|
||||
content = beforeNavigate(content);
|
||||
if (/^(https?|file):\/\//i.test(content)) {
|
||||
this.navigateToUrl(content, disposition);
|
||||
result = results.find(item => item.content === content);
|
||||
|
|
Loading…
Reference in a new issue