Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Part 16] Final. The remaining glue for new autocomplete ui binding #453

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

MareStare
Copy link
Contributor

@MareStare MareStare commented Mar 4, 2025

Before you begin

  • I understand my contributions may be rejected for any reason
  • I understand my contributions are for the benefit of Derpibooru and/or the Philomena software
  • I understand my contributions are licensed under the GNU AGPLv3
  • I understand all of the above

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

image

Tags search

image

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:

demo-suggsetion-first-character

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-3205418bde78

  • Integrate 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

  • Is the shortcuts' documentation page source somewhere in public? If not you should edit it to add some notes about the autocompletion shortcuts mentioned above.

@MareStare MareStare mentioned this pull request Mar 4, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant