diff --git a/docs/configuration.md b/docs/configuration.md index f547700..cabc454 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -725,10 +725,13 @@ Preview: | Ctrl + Enter | Perform search in a new tab | Search input is focused and not empty | | Escape | Leave focus | Search input is focused | +If property `new-tab` is set to `true`, keys Enter and Ctrl + Enter will be switched. + #### Properties | Name | Type | Required | Default | | ---- | ---- | -------- | ------- | | search-engine | string | no | duckduckgo | +| new-tab | boolean | no | false | | bangs | array | no | | ##### `search-engine` diff --git a/internal/assets/static/main.css b/internal/assets/static/main.css index 62b4480..fd76035 100644 --- a/internal/assets/static/main.css +++ b/internal/assets/static/main.css @@ -370,6 +370,10 @@ kbd:active { box-shadow: 0 0 0 0 var(--color-widget-background-highlight); } +new-tab { + display: none; +} + .content-bounds { max-width: 1600px; margin-inline: auto; diff --git a/internal/assets/static/main.js b/internal/assets/static/main.js index 3e10b96..d38db77 100644 --- a/internal/assets/static/main.js +++ b/internal/assets/static/main.js @@ -120,6 +120,7 @@ function setupSearchboxes() { const inputElement = widget.getElementsByClassName("search-input")[0]; const bangElement = widget.getElementsByClassName("search-bang")[0]; const bangs = widget.querySelectorAll(".search-bangs > input"); + const newTab = widget.getElementsByTagName("new-tab")[0].innerHTML === "true"; const bangsMap = {}; const kbdElement = widget.getElementsByTagName("kbd")[0]; let currentBang = null; @@ -154,7 +155,7 @@ function setupSearchboxes() { const url = searchUrlTemplate.replace("!QUERY!", encodeURIComponent(query)); - if (event.ctrlKey) { + if (newTab && !event.ctrlKey || !newTab && event.ctrlKey) { window.open(url, '_blank').focus(); } else { window.location.href = url; diff --git a/internal/assets/templates/search.html b/internal/assets/templates/search.html index a0dfaeb..998e133 100644 --- a/internal/assets/templates/search.html +++ b/internal/assets/templates/search.html @@ -20,5 +20,6 @@
S +