From ad5351cf0f575d739b7c9ab263ae886da977e22c Mon Sep 17 00:00:00 2001 From: Fabio Rufino Gallo Date: Tue, 17 Jul 2018 11:59:10 -0400 Subject: [PATCH] new strategy for detecting backspace --- index.js | 24 ++++++++++++++++++------ package.json | 6 +++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8ca7855..dc8d7c2 100644 --- a/index.js +++ b/index.js @@ -257,8 +257,21 @@ //BACKSPACE case 8: - if (this.query !== '') { - this.lookup(); + switch (this.query.length) { + case 0: // The user has removed the delimiter as well + this.cleanUp(true); + break; + case 1: // The user has removed everything except the delimiter. We need to remove some extra tags that TinyMce adds to keep the autocomplte working + var caret = this.editor.dom.select('span#autocomplete span#_mce_caret')[0]; + var searchtext = this.editor.dom.select('span#autocomplete span#autocomplete-searchtext')[0]; + this.editor.dom.add(caret.parentElement, searchtext); + this.editor.dom.remove(caret); + + this.editor.selection.select(this.editor.selection.dom.select('span#autocomplete-searchtext span')[0]); + this.editor.selection.collapse(0); + break; + default: + this.lookup(); } break; @@ -328,7 +341,6 @@ } }, - rteLostFocus: function () { if (this.hasFocus) { this.cleanUp(true); @@ -343,7 +355,7 @@ } this.query = this.jsH.trim(editorBody.innerText).replace('\ufeff', ''); - + if (this.dropdown === undefined) { this.show(); } @@ -357,11 +369,11 @@ } }.bind(this), this.options.delay); }, + matcher: function (item) { return ~item[this.options.queryBy].toLowerCase().indexOf(this.query.toLowerCase()); }, - sorter: function (items) { var beginswith = [], caseSensitive = [], @@ -452,7 +464,6 @@ } }, - renderDropdown: function () { return ''; //need to add a class starting with "mce-" to not make the inline editor disappear }, @@ -481,6 +492,7 @@ highlightNextResult: function () { this.highlightResult(1); }, + highlightResult: function (direction) { var activeLi = this.dropdown.querySelector('li.active'), items = Array.prototype.slice.call(this.dropdown.children), diff --git a/package.json b/package.json index 9ef3fec..62525d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "tinymce-mention-nojq", - "version": "4.0.3", + "name": "tinymce-mention-plugin", + "version": "4.0.4", "repository": { "type": "git", "url": "https://github.com/BlueprintSys/tinymce-mention-plugin" @@ -8,7 +8,7 @@ "description": "Mention/Autocomplete plugin for TinyMCE WYSIWYG editor (no jQuery dependent)", "author": "Steven Devooght", "bugs": { - "url": "https://github.com/BlueprintSys/tinymce-mention-nojq/issues" + "url": "https://github.com/BlueprintSys/tinymce-mention-plugin/issues" }, "main": "index.js", "license": "MIT"