Skip to content
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

Instant username autocompletion broken #68

Closed
DeanStr opened this issue Jan 12, 2018 · 2 comments
Closed

Instant username autocompletion broken #68

DeanStr opened this issue Jan 12, 2018 · 2 comments

Comments

@DeanStr
Copy link

DeanStr commented Jan 12, 2018

It seems switching to trix has broken instant username autocompletion.

@M-Hoogie
Copy link
Contributor

Soooo, I have a solution for the @mentions but am encountering a bug with the atwho-view (the list items)

So if you would use remoteFilter and use callback(['Mark', 'Jeffrey', 'Dean']) the positioning of atwho-view will be correct. But when you use axios or any other ajax call. The positioning will be top: -18px; left: 0

Anyway this is the code I am using in the Wysiswyg component in the mounted event.

let $vm = this;

$('trix-editor').atwho({
  at: "@",
  delay: 750,
  callbacks: {
    remoteFilter: function(query, callback) {
      axios.get(`/api/users?name=${query}`).then(function({data}) {
        callback(data);
      });
     }
   },
})
.on('matched.atwho', function(e, flag, query) {
  $vm.query = query;
})
.on('inserted.atwho', function(el, li, e) {
  // Get editor.
  let editor = el.currentTarget.editor;
  // set selected rang
   let range = editor.getSelectedRange();
   editor.setSelectedRange([range[0] - $vm.query.length, range[1]]);
  // delete typed text and insert the matched item
   editor.deleteInDirection("forward");
   editor.insertString(li[0].innerText);
});

@JeffreyWay
Copy link
Owner

Closing in favor of the #69 PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants