quill icon indicating copy to clipboard operation
quill copied to clipboard

Has anyone had any luck integrating with a mentions library like AT.js?

Open chrislentz opened this issue 10 years ago • 16 comments

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?

chrislentz avatar Sep 10 '16 15:09 chrislentz

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.

saw avatar Sep 10 '16 18:09 saw

Here's an example of handling @ mentions with a pop-up autocompletion list: codepen

felipeochoa avatar Nov 01 '16 01:11 felipeochoa

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.

tjrobertsnz avatar Feb 18 '17 22:02 tjrobertsnz

@felipeochoa your code doesn't work on a PC keyboard, the '@' doesn't have the same keyCode, did you find a workaround ?

guillaumecodet avatar Feb 20 '17 14:02 guillaumecodet

@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.

micheledicosmo avatar Apr 07 '17 16:04 micheledicosmo

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:

felipeochoa avatar Apr 07 '17 16:04 felipeochoa

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.

adamkdean avatar Jun 01 '17 08:06 adamkdean

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 avatar Jun 28 '17 20:06 mkallies

@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 avatar Jul 17 '17 12:07 nitaskenderi

@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 avatar Jul 17 '17 16:07 mkallies

@mkallies thank you so much for sharing your solution, this has totally fixed my problem!

nitaskenderi avatar Jul 18 '17 08:07 nitaskenderi

Could someone post a working example please.

monstrfolk avatar Aug 03 '17 06:08 monstrfolk

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.

johnozbay avatar Dec 11 '17 12:12 johnozbay

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.

eltimn avatar Feb 09 '18 15:02 eltimn

@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 avatar Apr 22 '20 06:04 rohitsaha-handysolver

@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.

nitaskenderi avatar Apr 22 '20 08:04 nitaskenderi