You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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?
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.
I've been doing some prototyping using (new wp.api.collections.Users()).fetch().then(...).
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.
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.
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.
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).
@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.
Activity
karmatosed commentedon Sep 27, 2017
Design wise, following the pattern we have for slash commands seems the solid way forward.
If we know things like avatars (users on site), then we can pull them through. What do people think?
mtias commentedon Sep 27, 2017
In general I'm imagining the tokenization being first-class in tinymce (this might also be useful in the context of footnotes). Something like
@usernamesupport requires more infrastructure in terms of what happens when someone is mentioned that is not available in core.BoardJames commentedon Sep 27, 2017
@karmatosed thanks for the mock-up.
BoardJames commentedon Sep 28, 2017
I've been doing some prototyping using

(new wp.api.collections.Users()).fetch().then(...).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.
camya commentedon Oct 11, 2017
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.
BoardJames commentedon Oct 11, 2017
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.
BoardJames commentedon Oct 19, 2017
I have the hash-tag autocompleter in the branch add/2793-hashlink-autocompletion - once I have #2896 merged I will put in another PR.
helen commentedon Jan 11, 2018
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:
@displaynameas 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(nameandslugI 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?rolesandnumberusingrest_user_query, I was not getting a$requestobject for context (and therefore getting a PHP notice about a missing argument).adamsilverstein commentedon Jan 11, 2018
@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.
jeffpaul commentedon Jan 26, 2018
This ticket was mentioned in Slack in #core-editor by jeffpaul. View the logs.
mtias commentedon Mar 6, 2018
Closing this as improvements have landed and others are being worked on, like #4609.