Skip to content

Autocompletion of #hash-tags or @users #2793

Closed

Description

@BoardJames

Overview

One of the tasks I've been asked to complete by @annaephox via @karmatosed is to add auto-completion actions for '#' for hash tags and '@' for user mentions. An auto completion feature has already been implemented for custom block selection using '/' so I am assuming I will be using that feature.

I am creating this issue because I need guidance on how to gather the information that should go in the auto complete menu.

I am hoping that @karmatosed or others could provide further information or mock-ups to guide what is desired.

Hash tag

I am not sure what is desired with hash-tags. Should they auto-complete from the list of post tags? Should they add new entries to the post tags? Should they link to the archive page for that tag?

If they are post tags then should they be exported from PHP land with https://codex.wordpress.org/Function_Reference/wp_get_post_tags ? Is there a better way?

User mentions

User mentions worry me because I am wary of leaking potentially sensitive information (like the user-names of Wordpress logins). It seems that I could get a list of users using https://codex.wordpress.org/Function_Reference/get_users and export them to Javascript land. If I did go that route then should the user mention autocomplete search the user_login or user_nicename? Should the link created link to the email address or web URL of the user? Is there a better listing of usernames somewhere that I could autocomplete from?

Activity

  1. self-assigned this
    on Sep 26, 2017
  2. karmatosed commented on Sep 27, 2017

    @karmatosed
    Member

    Design wise, following the pattern we have for slash commands seems the solid way forward.

    mentions

    If we know things like avatars (users on site), then we can pull them through. What do people think?

  3. mtias commented on Sep 27, 2017

    @mtias
    Member

    In general I'm imagining the tokenization being first-class in tinymce (this might also be useful in the context of footnotes). Something like @username support requires more infrastructure in terms of what happens when someone is mentioned that is not available in core.

  4. BoardJames commented on Sep 27, 2017

    @BoardJames
    Author

    @karmatosed thanks for the mock-up.

    • Where do I get the user list from?
    • Where do I get the tag list from?
  5. BoardJames commented on Sep 28, 2017

    @BoardJames
    Author

    I've been doing some prototyping using (new wp.api.collections.Users()).fetch().then(...).
    mention

    Currently the autocomplete that already exists assumes that the block that the autocomplete is on is empty so the pop-up is always positioned at the left hand side.

  6. camya commented on Oct 11, 2017

    @camya

    General "Insert Link" Autocomplete (using #Hash-Tag)

    Maybe it's possible to create a #Hash-Tag Auto-completion which inserts all kind of "Links" directly to a block. (These can be links to posts, pages, named anchors (IDs), tags, categories.)

    Example block text: "Don't miss to read my previous #cars" (-> opens tabbed dropdown with posts, pages, tags, categories, named anchors which matches the word "cars") If the user selects the dropdown entry, the link is inserted into the block. After inserting a link with the Autocomplete, the regular "Link" dialog will be shown to alter the settings for the link.

  7. BoardJames commented on Oct 11, 2017

    @BoardJames
    Author

    I like that idea - I think I can get most of those things from wp.api.collections which has lookups for Posts, PostRevisions, Pages, PageRevisions, Media, Types, Statuses, Taxonomies, Categories, Tags, Users and Comments. So I'd just have to query a few of them. When get the details of the system worked out for the user autocomplete I will do the hash tag autocomplete.

  8. BoardJames commented on Oct 19, 2017

    @BoardJames
    Author

    I have the hash-tag autocompleter in the branch add/2793-hashlink-autocompletion - once I have #2896 merged I will put in another PR.

  9. helen commented on Jan 11, 2018

    @helen
    Member

    I’m working on making sure we can use Gutenberg on an internal comms site that uses @ user mentions but not via P2/O2, and ran across a few things that are semi-blockers for me and could either use some advice or perhaps serve as fodder for further refinements, as this looks like an early POC-style implementation to me:

    • The search functionality only actually searches on the client side through the current set of results, as opposed to sending a search string.
    • The current set of results by default is just 10 of the users for the site, and since it doesn’t filter down using a search string or anything, it’s always just the same 10 (or fewer) users.
    • Using @displayname as the text for the link makes some amount of sense, and I don’t really have a strong opinion on what the default should be, but in our case we need it to be @username (name and slug I think I saw them called in the code). What would be the proper way of altering what’s inserted upon selection of an autocomplete item?
    • On multisite, users without a role for the site are included. This is actually typical of WordPress’s handling of “no role for site” which is generally counterintuitive, so I’m not sure this feature has to account for that. Rather, there needs to be a way to filter/alter the user query in a targeted way.
    • This may be a case of developer error, but in working on altering the query args for roles and number using rest_user_query, I was not getting a $request object for context (and therefore getting a PHP notice about a missing argument).
  10. adamsilverstein commented on Jan 11, 2018

    @adamsilverstein
    Member

    @helen I have addressed the first two points of your feedback in #4406 - not sure about the other questions around extensibility/altering the default behavior from a developer perspective.

  11. added
    [Type] Enhancement
    [Status] In Progress
    on Jan 26, 2018
  12. jeffpaul commented on Jan 26, 2018

    @jeffpaul
    Member

    This ticket was mentioned in Slack in #core-editor by jeffpaul. View the logs.

  13. mtias commented on Mar 6, 2018

    @mtias
    Member

    Closing this as improvements have landed and others are being worked on, like #4609.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Status] In Progress[Type] Enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions