Added the local setting to disable auto-completion

This commit is contained in:
KoloMl 2024-06-02 20:40:09 +04:00
parent 7fa141bb54
commit 1a7d59cb59
3 changed files with 17 additions and 0 deletions

View file

@ -5,6 +5,7 @@
import { LocalAutocompleter } from './utils/local-autocompleter'; import { LocalAutocompleter } from './utils/local-autocompleter';
import { handleError } from './utils/requests'; import { handleError } from './utils/requests';
import { getTermContexts } from './match_query'; import { getTermContexts } from './match_query';
import store from './utils/store';
const cache = {}; const cache = {};
/** @type {HTMLInputElement} */ /** @type {HTMLInputElement} */
@ -184,6 +185,15 @@ function getSelectedTerm() {
return terms.find(([range]) => range[0] < selectionIndex && range[1] >= selectionIndex); return terms.find(([range]) => range[0] < selectionIndex && range[1] >= selectionIndex);
} }
function toggleSearchAutocomplete() {
if (!store.get('disable_search_ac')) return;
for (const searchField of document.querySelectorAll('input[data-ac-mode=search]')) {
searchField.removeAttribute('data-ac');
searchField.autocomplete = 'on';
}
}
function listenAutocomplete() { function listenAutocomplete() {
let timeout; let timeout;
@ -268,6 +278,8 @@ function listenAutocomplete() {
.then(buf => localAc = new LocalAutocompleter(buf)); .then(buf => localAc = new LocalAutocompleter(buf));
} }
} }
toggleSearchAutocomplete();
} }
export { listenAutocomplete }; export { listenAutocomplete };

View file

@ -45,6 +45,7 @@ defmodule PhilomenaWeb.SettingController do
|> set_cookie(user_params, "hide_uploader", "hide_uploader") |> set_cookie(user_params, "hide_uploader", "hide_uploader")
|> set_cookie(user_params, "hide_score", "hide_score") |> set_cookie(user_params, "hide_score", "hide_score")
|> set_cookie(user_params, "unfilter_tag_suggestions", "unfilter_tag_suggestions") |> set_cookie(user_params, "unfilter_tag_suggestions", "unfilter_tag_suggestions")
|> set_cookie(user_params, "disable_search_ac", "disable_search_ac")
end end
defp set_cookie(conn, params, param_name, cookie_name) do defp set_cookie(conn, params, param_name, cookie_name) do

View file

@ -174,6 +174,10 @@ h1 Content Settings
=> label f, :chan_nsfw, "Show NSFW channels" => label f, :chan_nsfw, "Show NSFW channels"
=> checkbox f, :chan_nsfw, checked: @conn.cookies["chan_nsfw"] == "true" => checkbox f, :chan_nsfw, checked: @conn.cookies["chan_nsfw"] == "true"
.fieldlabel: i Show streams marked as NSFW on the channels page. .fieldlabel: i Show streams marked as NSFW on the channels page.
.field
=> label f, :disable_search_ac, "Disable search auto-completion"
=> checkbox f, :disable_search_ac, checked: @conn.cookies["disable_search_ac"] === "true"
.fieldlabel: i Disable the auto-completion of tags in the search fields. This will bring back default browser's behaviour.
= if staff?(@conn.assigns.current_user) do = if staff?(@conn.assigns.current_user) do
.field .field
=> label f, :hide_staff_tools => label f, :hide_staff_tools