-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add/2793 hashlink autocompletion #3324
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3324 +/- ##
==========================================
- Coverage 35.29% 35.21% -0.08%
==========================================
Files 267 267
Lines 6744 6758 +14
Branches 1221 1221
==========================================
Hits 2380 2380
- Misses 3687 3701 +14
Partials 677 677
Continue to review full report at Codecov.
|
blocks/autocompleters/index.js
Outdated
@@ -125,3 +132,56 @@ export function userAutocompleter() { | |||
onSelect, | |||
}; | |||
} | |||
|
|||
export function hashtagAutocompleter() { | |||
const c = wp.api.collections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring can help here to avoid using abbreviated c
const:
const { Categories, Pages, Posts, Tags } = wp.api.collections;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
I love this! Very very cool. Could work here be expanded to username autocompletion with This should probably be limited to searching tags, though, less so categories and pages. Those are perhaps best linked using the search tool in the link box. I also got multi select to invoke by not doing a plain click but a click drag in the menu: There's also been talk about "syntactic sugar" — that is, using markdown shortcuts for some blocks. In this case we'd want this search tool to only invoke on |
I'm being told that user auto completion is As you were. |
@EphoxJames The most common use of linking to anchors within the same document would probably be linking to headings. For that to happen, we would have to auto-assign IDs to each heading and have those IDs included on the front-end. Currently headings get an ID like
@jasmussen I'm not sure what you mean here. Would it really be that common to link to tag archives? To me, the use of |
Hashtag autocompletion is a common pattern on Facebook, Twitter, P2 and many other social platforms. It'd be a nice feature to have for a modularized Gutenberg. Given you can already add HTML anchors to headings in Gutenberg, I'm not sure an autocomplete for reusing anchors makes a ton of sense to prioritize. |
You can use |
I've done some work on making the ESC keep the popover hidden on #3343 |
From reading the feedback I will:
Currently I am not aware of any API to filter the lists before sending them from the server so lots of content is a valid concern but I don't know how to solve it. The API request on new '#' was a deliberate design decision on the autocompleter - I originally only requested the data once per page load per autocompleter but review highlighted this as incorrect so I changed it to request on opening an autocompleter. |
Ok, I just tried displaying the list only after one character and it feels unresponsive. I then when looking for existing implementations and both facebook and slack display the menu straight away. So I am not going to implement that. |
I have sorted the entries within each type alphabetically. |
I should note that the reason this hasn't had progress recently is that I am trying to find a way of writting automated tests for it. I initially tried writing unit tests mocking out the collections api but I wasn't happy with how much I was having to mock so I stopped that and tried writing a end-to-end test. Unfortunately it seems that Cypress is unable to simulate selection properly so I could not get a autocompleter popup to display (I should note that the existing Cypress test of the block autocompleter is not actually working despite passing). I then tried putting together a selenium test and it worked very well but I still haven't figured out an elegent way to integrate that into the project. So what do people think? This has been manually tested so should I merge it, or wait until I can find a way of automating the test? |
Any update on this one, could we have the feature without the tests for now? |
Feel free to take over the PR if you wish. |
If we land #4609, it would be easier to test since data retrieval would be separated from rendering. We might not test data retrieval, but we could test rendering, generation of keywords, etc. If that sounds reasonable, I'm up for taking this as a follow up. |
There was no activity in this PR for over 6 months. It looks like it was abandoned. Let’s close it. We can always reopen and rebase it with master branch to align with the current state of Gutenberg. |
Description
This implements link autocompletion with '#' as the trigger. It can link to posts, pages, tags or categories. If possible I'd like to also suggest anchors within the document which might be possible with an appropriate querySelectorAll call (suggestions on how that would work are welcome).
At the moment I'd like feedback on if this is the right sort of information to display in the autocomplete.
How Has This Been Tested?
I've tried it out in a few browsers though I should probably do a more rigorous test before merge.
Screenshots (jpeg or gifs if applicable):
Types of changes
New feature.
Checklist: