diff --git a/assets/js/autocomplete.js b/assets/js/autocomplete.js index b9ca92c5..978c7cab 100644 --- a/assets/js/autocomplete.js +++ b/assets/js/autocomplete.js @@ -5,6 +5,7 @@ import { LocalAutocompleter } from './utils/local-autocompleter'; import { handleError } from './utils/requests'; import { getTermContexts } from './match_query'; +import store from './utils/store'; const cache = {}; /** @type {HTMLInputElement} */ @@ -184,6 +185,15 @@ function getSelectedTerm() { 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() { let timeout; @@ -268,6 +278,8 @@ function listenAutocomplete() { .then(buf => localAc = new LocalAutocompleter(buf)); } } + + toggleSearchAutocomplete(); } export { listenAutocomplete }; diff --git a/lib/philomena_web/controllers/setting_controller.ex b/lib/philomena_web/controllers/setting_controller.ex index 7c3d6db9..ce8aec3d 100644 --- a/lib/philomena_web/controllers/setting_controller.ex +++ b/lib/philomena_web/controllers/setting_controller.ex @@ -45,6 +45,7 @@ defmodule PhilomenaWeb.SettingController do |> set_cookie(user_params, "hide_uploader", "hide_uploader") |> set_cookie(user_params, "hide_score", "hide_score") |> set_cookie(user_params, "unfilter_tag_suggestions", "unfilter_tag_suggestions") + |> set_cookie(user_params, "disable_search_ac", "disable_search_ac") end defp set_cookie(conn, params, param_name, cookie_name) do diff --git a/lib/philomena_web/templates/setting/edit.html.slime b/lib/philomena_web/templates/setting/edit.html.slime index 92e13038..fd6677bb 100644 --- a/lib/philomena_web/templates/setting/edit.html.slime +++ b/lib/philomena_web/templates/setting/edit.html.slime @@ -174,6 +174,10 @@ h1 Content Settings => label f, :chan_nsfw, "Show NSFW channels" => checkbox f, :chan_nsfw, checked: @conn.cookies["chan_nsfw"] == "true" .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 .field => label f, :hide_staff_tools