[feat] client/simple: move cursor to end of search input on mobile

On mobile devices, when the search input is focused, move the cursor
to the end of the existing text. This improves the user experience by
making it easier to edit or append to the current query without
manually moving the cursor first.

Closes: https://github.com/searxng/searxng/issues/5112
This commit is contained in:
Amit Katyal 2025-08-20 15:38:54 +05:30 committed by Markus Heiser
parent 22c2c93274
commit 5ca70ca17e

View file

@ -40,6 +40,18 @@ if (!(isMobile || isResultsPage)) {
qInput.focus();
}
// On mobile, move cursor to the end of the input on focus
if (isMobile) {
listen("focus", qInput, () => {
// Defer cursor move until the next frame to prevent a visual jump
requestAnimationFrame(() => {
const end = qInput.value.length;
qInput.setSelectionRange(end, end);
qInput.scrollLeft = qInput.scrollWidth;
});
});
}
createClearButton(qInput);
// Additionally to searching when selecting a new category, we also