Merge pull request #4 from sijad/emoji-popup

Improve emoji popup
This commit is contained in:
Toby Zerner 2016-02-22 21:46:03 +10:30
commit 6e414568db
2 changed files with 14 additions and 8 deletions

View File

@ -176,15 +176,18 @@ System.register('flarum/emoji/addComposerAutocomplete', ['flarum/extend', 'flaru
if (this.selectionEnd - cursor > 0) return;
// Search backwards from the cursor for an ':' symbol, without any
// intervening whitespace. If we find one, we will want to show the
// Search backwards from the cursor for an ':' symbol. If we find
// one and followed by a whitespace, we will want to show the
// autocomplete dropdown!
var value = this.value;
emojiStart = 0;
for (var i = cursor - 1; i >= 0; i--) {
var character = value.substr(i, 1);
if (/\s/.test(character)) break;
if (character === ':') {
// check what user typed, emoji names only contains alphanumeric,
// underline, '+' and '-'
if (!/[a-z0-9]|\+|\-|_|\:/.test(character)) break;
// make sure ':' followed by a whitespace
if (character === ':' && (i == 0 || value.substr(i - 1, 1) === ' ')) {
emojiStart = i + 1;
break;
}

View File

@ -44,15 +44,18 @@ export default function addComposerAutocomplete() {
if (this.selectionEnd - cursor > 0) return;
// Search backwards from the cursor for an ':' symbol, without any
// intervening whitespace. If we find one, we will want to show the
// Search backwards from the cursor for an ':' symbol. If we find
// one and followed by a whitespace, we will want to show the
// autocomplete dropdown!
const value = this.value;
emojiStart = 0;
for (let i = cursor - 1; i >= 0; i--) {
const character = value.substr(i, 1);
if (/\s/.test(character)) break;
if (character === ':') {
// check what user typed, emoji names only contains alphanumeric,
// underline, '+' and '-'
if (!/[a-z0-9]|\+|\-|_|\:/.test(character)) break;
// make sure ':' followed by a whitespace
if (character === ':' && (i == 0 || value.substr(i-1, 1) === ' ')) {
emojiStart = i + 1;
break;
}