🔀 Merge pull request #1915 from aspenyang/opt1-search

Search box url detection and open link feature #1881
Fixes #1881
This commit is contained in:
Alicia Sykes 2026-03-10 12:30:53 +00:00 committed by GitHub
commit c2b2eb5913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 4 deletions

View file

@ -219,6 +219,7 @@ For more info, see the **[Authentication Docs](/docs/authentication.md)**
**`customSearchEngine`** | `string` | _Optional_ | You can also use a custom search engine, or your own self-hosted instance. This requires `searchEngine: custom` to be set. Then add the URL of your service, with GET query string included here
**`openingMethod`** | `string` | _Optional_ | Set your preferred opening method for search results: `newtab`, `sametab`, `workspace`. Defaults to `newtab`
**`searchBangs`** | `object` | _Optional_ | A key-value-pair set of custom search _bangs_ for redirecting query to a specific app or search engine. The key of each should be the bang you will type (typically starting with `/`, `!` or `:`), and value is the destination, either as a search engine key (e.g. `reddit`) or a URL with search parameters (e.g. `https://en.wikipedia.org/w/?search=`)
**`openUrlsDirectly`** | `boolean` | _Optional_ | If `true`, queries that look like URLs will be opened directly instead of searched. Defaults to `false`
**[⬆️ Back to Top](#configuring)**

View file

@ -114,6 +114,18 @@ appConfig:
webSearch: { disableWebSearch: true }
```
### Opening URLs Directly
When enabled, if your search query looks like a URL (e.g. `github.com`, `https://example.org/path`), pressing <kbd>Enter</kbd> will navigate directly to that URL instead of searching for it.
Set `appConfig.webSearch.openUrlsDirectly` to `true`:
```yaml
appConfig:
webSearch:
openUrlsDirectly: true
```
## Clearing Search
You can clear your search term at any time, resting the UI to it's initial state, by pressing <kbd>Esc</kbd>.

View file

@ -8,7 +8,8 @@
"search-label": "Search",
"search-placeholder": "Start typing to filter",
"clear-search-tooltip": "Clear Search",
"enter-to-search-web": "Press enter to search the web"
"enter-to-search-web": "Press enter to search the web",
"enter-to-open-url": "Press enter to open URL"
},
"splash-screen": {
"loading": "Loading"

View file

@ -9,8 +9,8 @@
:placeholder="$t('search.search-placeholder')"
v-on:input="userIsTypingSomething"
@keydown.esc="clearFilterInput" />
<p v-if="(!searchPrefs.disableWebSearch) && input.length > 0" class="web-search-note">
{{ $t('search.enter-to-search-web') }}
<p v-if="searchNote && input.length > 0" class="web-search-note">
{{ searchNote }}
</p>
</div>
<i v-if="input.length > 0"
@ -52,6 +52,14 @@ export default {
searchPrefs() {
return this.$store.getters.webSearch || {};
},
urlDetected() {
return this.searchPrefs.openUrlsDirectly && this.isUrlLike(this.input.trim());
},
searchNote() {
if (this.urlDetected) return this.$t('search.enter-to-open-url');
if (!this.searchPrefs.disableWebSearch) return this.$t('search.enter-to-search-web');
return '';
},
},
mounted() {
window.addEventListener('keydown', this.handleKeyPress);
@ -126,8 +134,16 @@ export default {
// Get search preferences from appConfig
const { searchPrefs } = this;
if (!searchPrefs.disableWebSearch) { // Only proceed if user hasn't disabled web search
const bangList = { ...defaultSearchBangs, ...(searchPrefs.searchBangs || {}) };
const input = this.input.trim();
const openingMethod = searchPrefs.openingMethod || defaultSearchOpeningMethod;
// If openUrlsDirectly enabled and input looks like a URL, navigate directly
if (searchPrefs.openUrlsDirectly && input && this.isUrlLike(input)) {
const url = /^https?:\/\//.test(input) ? input : `https://${input}`;
this.launchWebSearch(url, openingMethod);
this.clearFilterInput();
return;
}
const bangList = { ...defaultSearchBangs, ...(searchPrefs.searchBangs || {}) };
const searchBang = getSearchEngineFromBang(this.input, bangList);
const searchEngine = searchPrefs.searchEngine || defaultSearchEngine;
// Use either search bang, or preffered search engine
@ -143,6 +159,10 @@ export default {
}
}
},
/* Detect if input looks like a URL (has TLD, no spaces) */
isUrlLike(input) {
return /^(https?:\/\/)?([\w-]+\.)+[a-zA-Z]{2,}(\/\S*)?$/.test(input.trim());
},
},
};
</script>

View file

@ -351,6 +351,12 @@
"default": "false",
"description": "If set to true, web search will be disabled all together"
},
"openUrlsDirectly": {
"title": "Open URLs Directly",
"type": "boolean",
"default": false,
"description": "If enabled, when the search query looks like a URL it will be opened directly instead of being passed to the search engine"
},
"searchEngine": {
"title": "Search Engine",
"type": "string",