From c6b07852fefb1e950b72a484e5d67d0960a4b864 Mon Sep 17 00:00:00 2001
From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com>
Date: Sat, 16 Nov 2024 08:29:58 +0000
Subject: [PATCH] Clear search input on submission
---
docs/configuration.md | 1 +
internal/assets/static/js/main.js | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/docs/configuration.md b/docs/configuration.md
index 0cd44cf..f8221b8 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -846,6 +846,7 @@ Preview:
| Enter | Perform search in the same tab | Search input is focused and not empty |
| Ctrl + Enter | Perform search in a new tab | Search input is focused and not empty |
| Escape | Leave focus | Search input is focused |
+| Up | Insert the last search query since the page was opened into the input field | Search input is focused |
> [!TIP]
>
diff --git a/internal/assets/static/js/main.js b/internal/assets/static/js/main.js
index 25d78ca..ff26caa 100644
--- a/internal/assets/static/js/main.js
+++ b/internal/assets/static/js/main.js
@@ -105,6 +105,7 @@ function setupSearchBoxes() {
const bangsMap = {};
const kbdElement = widget.getElementsByTagName("kbd")[0];
let currentBang = null;
+ let lastQuery = "";
for (let j = 0; j < bangs.length; j++) {
const bang = bangs[j];
@@ -141,6 +142,14 @@ function setupSearchBoxes() {
window.location.href = url;
}
+ lastQuery = query;
+ inputElement.value = "";
+
+ return;
+ }
+
+ if (event.key == "ArrowUp" && lastQuery.length > 0) {
+ inputElement.value = lastQuery;
return;
}
};