Skip to content

Commit

Permalink
Merge pull request #1 from vdtn359/master
Browse files Browse the repository at this point in the history
Fixed bugs in mention plugin
  • Loading branch information
vdtn359 authored Nov 19, 2018
2 parents 8653f49 + 76d7449 commit a0ad580
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions mention/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,18 @@
},

lookup: function () {
this.query = $.trim($(this.editor.getBody()).find('#autocomplete-searchtext').text()).replace('\ufeff', '');
var body = $(this.editor.getBody());
var autoCompleteSearchText = body.find('#autocomplete-searchtext');
this.query = $.trim(autoCompleteSearchText.text()).replace('\ufeff', '');
if (this.query === '') {
var autoComplete = body.find('#autocomplete');
if (autoComplete.length) {
autoCompleteSearchText.appendTo(autoComplete);
this.editor.selection.select(autoCompleteSearchText.find('span')[0]);
} else {
this.cleanUp(true);
}
}

if (this.$dropdown === undefined) {
this.show();
Expand Down Expand Up @@ -253,11 +264,21 @@

items = _this.sorter(items);

items = items.slice(0, this.options.items);
if (this.options.items === -1) {
items = items.slice();
} else {
items = items.slice(0, this.options.items);
}

$.each(items, function (i, item) {
var $element = $(_this.render(item, i));

var textNodes = $element.find('*').andSelf().contents().filter(function() {
return this.nodeType === 3; //Node.TEXT_NODE
}).each(function(index, element) {
$(element).parent().html(_this.highlighter(element.textContent));
});

$element.html($element.html().replace($element.text(), _this.highlighter($element.text())));

$.each(items[i], function (key, val) {
Expand All @@ -269,6 +290,7 @@

if (result.length) {
this.$dropdown.html(result.join('')).show();
this.highlightNextResult();
} else {
this.$dropdown.hide();
this.$dropdown.find('li').removeClass('active');
Expand Down
2 changes: 1 addition & 1 deletion mention/plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0ad580

Please sign in to comment.