Has anyone had any luck integrating with a mentions library like AT.js?
I am looking to utilize quill on my site, but I need the ability to support mention abilities. i.e. "@" mentions and "#" hashtag lookup.
I am currently exploring integrating with https://github.com/ichord/At.js or https://github.com/yuku-t/jquery-textcomplete.
Has anyone had any luck adding this sort of functionality to quill 1.0?
We are exploring it. The easy way is to watch for text changes and when you see a ":" fire up your modal or whatever and when you are done insert the text into the editor.
Here's an example of handling @ mentions with a pop-up autocompletion list: codepen
How did you end up doing this @chrislentz? I'm considering Quill for an app I'm building, @ and # tagging will be key components to wondering whether you successfully implemented with Quill in the end or went down another route.
@felipeochoa your code doesn't work on a PC keyboard, the '@' doesn't have the same keyCode, did you find a workaround ?
@chrislentz @felipeochoa Did you succeed? I'm also starting some implementation today and would be nice to create a proper module for Quill joining our knowledge.
I've made some changes to the above, latest can be found in this gist. It was a quick copy-paste from my code, some some bits may be slightly off, but should be 99% there.
@guillaumecodet I submitted #1091 a while ago, but unfortunately that got rejected. Without that, there's really no good way of binding in keyboard-independent manner. So anyone who has @ somewhere other than Shift+2 is going to be confused :disappointed:
To use this At.js I had to grab the already typed data the html in $li.data('item-data'), then use getContents to get both the delta up to the selection index, and the delta after it, minus anything already typed, then I'd sandwich a new insert op inbetween those two op arrays.
It's not the best solution, but it's what had to be done. I also had to manually set the selection index (lastTextChangeIndex below) on text-change because Quill is unreliable with it's getRange.
var before = thisQuill.getContents(0, lastTextChangeIndex - removeLength);
var after = thisQuill.getContents(lastTextChangeIndex + 1);
var ops = before.ops.concat([
{ insert: content }
]).concat(after.ops);
thisQuill.setContents(ops);
thisQuill.setSelection(lastTextChangeIndex + content.length, 0, Quill.sources.USER);
Hope this helps anyone also stuck.
Anyone have cursor issues with At.js? If you have the dropdown with the possible mentions, moving the cursor will make it jump either to the end of the line or to the beginning
@mkallies I also have this issue and according to the tests I have done, I have noticed that the quill getSelection() does not return the correct caret index and I think this is due to the span.atwho-query, whom Quill does not recognize.
@adamkdean how do you get the lastTextChangeIndex? I want to try your method but I am not sure how you get this value?
@nitaskenderi we forked At.js and removed the click, left and right arrow listeners. Super PITA with IE11, contenteditable and At.js.
Instead of adam's solution, we just added support for the <span>'s since Quill will remove it if it doesnt recognize them.
const Parchment = Quill.import('parchment');
const Query = new Parchment.Attributor.Class('custom', 'atwho', { scope:
Parchment.Scope.INLINE_BLOT, whitelist: ['query', 'inserted'] });
Quill.register(Query, true);
@mkallies thank you so much for sharing your solution, this has totally fixed my problem!
Could someone post a working example please.
There's a working example using tribute. Take a look at this : #1816
It seems to be working out of the box with Quill. Implementation has a few hiccups, but looks like it can all be worked out with the help of the two communities. I've successfully implemented this solution, and it's working smoothly.
I just wanted to let anyone coming here know that there are now two viable Quill mentions modules:
The former has no dependencies, is only 5k compressed, and, most importantly for me, uses an Embed blot.
I only played around with the latter for a little while but it seemed to have more features. However, I need to store the user's id with the mention, so I need something that uses an Embed.
@nitaskenderi can you please tell me and provide working example how you solved this jumping issue in quill and atwho. below is what i haven used which i got from some where it insert but have jumping issue ``
$(".ql-editor").atwho({ at: '@', data:"user array", functionOverrides: { insert: function(text) { console.log(text) let range = quill.getSelection(); quill.insertText(range.index, text, Quill.sources.USER); sendEmailToMentionedUser(quill.getText()); } } });
@rohitsaha-handysolver I'm sorry but I do not have access to that code anymore and it was such a long time ago that I do not remember the specifics of my solution. But, as far as I can remember, I think I removed the click, left and right arrow listeners and added support for atwho's <span>s, as per @mkallies comment.