[Part 16] Final. The remaining glue for new autocomplete ui binding #453
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before you begin
50% of the diff in this PR are just integration tests.
Added support for search history recording via
localStorage
to the main site image search inputs. I also did an extensive rewrite of the existing autocomplete code to make it more organized and type-coherent.The lower search bar on the
/search
page also shows history:If the user types at least one non-whitespace character we display at most 3 history suggestions at the top based on the prefix match.
When the input is empty and focused, we display the 10 last recently used queries:
New Autocompletion-Enabled Inputs
Added
data-autocompletion*
attributes without history recording to the following inputs:Artist link request
Tags search
Shortucts
Form Submission
Clicking or pressing Enter on the history item submits the form right away. If the user wants to continue typing after the history item and prevent submitting the form, they can do so by using Shift+Enter or with a Shift+LMB. This is a big deviation from the tag's completions because I believe most of the time the intention of selecting the history item is to submit it immediately. This decision is arguable, but we can tweak this behaviour as needed based on feedback.
An opposite shortcut Ctrl+Enter or Ctrl+LMB can now be used both with history and tag suggestions to submit the form immediately with the provided suggestion inserted.
Other Deviations from the Current Behavior
Now there are tag suggestions when the cursor is right before the first character of the term:
Future Extensions
These changes aren't implemented and are left for the scope of the follow-up PRs:
Support deleting items from the history and purging them. This is must have before history suggestions are enabled by default for all users. It will be most useful to delete annoying history records with typos or queries submitted by mistake.
Fix local settings state handling. Remove cookies and the save button from there, because these settings need to be stored in
localStorage
exclusively. A demo of this bug: https://github.com/user-attachments/assets/db315bc5-520a-4887-b4b8-3205418bde78Integrate the inserted suggestion into the user's text undo stack. I.e. Ctrl+Z should cancel the previously inserted suggestion. This requires
document.execCommand
, but that API is deprecated with no alternatives (!), but we can use it in the absence of better APIs.Prioritize canonical tags in server-side completions. I.e. basically we need the solution implemented in Fixed aliases still displaying for namespaced tags, fixing the actual cause of the issue inside local autocomplete #420 but also implemented in the server-side completions
Support pinning (📌) history items to make sure they are always listed at the top of suggestions when the input is empty (not sure anyone would want this feature, just sharing some crazy ideas).
Unresolved Questions