From 15a87c55ebb733a801775afd5c770fc7471fd9eb Mon Sep 17 00:00:00 2001 From: Sajjad Hasehmian Date: Fri, 12 Feb 2016 20:04:37 +0330 Subject: [PATCH 1/2] improve emoji popup --- extensions/emoji/js/forum/dist/extension.js | 4 ++-- extensions/emoji/js/forum/src/addComposerAutocomplete.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/emoji/js/forum/dist/extension.js b/extensions/emoji/js/forum/dist/extension.js index 8308f9f0f..de0045cbb 100644 --- a/extensions/emoji/js/forum/dist/extension.js +++ b/extensions/emoji/js/forum/dist/extension.js @@ -183,8 +183,8 @@ System.register('flarum/emoji/addComposerAutocomplete', ['flarum/extend', 'flaru emojiStart = 0; for (var i = cursor - 1; i >= 0; i--) { var character = value.substr(i, 1); - if (/\s/.test(character)) break; - if (character === ':') { + if (!/[a-z0-9]|\+|\-|_|\:/.test(character)) break; + if (character === ':' && (i == 0 || value.substr(i - 1, 1) === ' ')) { emojiStart = i + 1; break; } diff --git a/extensions/emoji/js/forum/src/addComposerAutocomplete.js b/extensions/emoji/js/forum/src/addComposerAutocomplete.js index ff0bc3379..b878b3806 100644 --- a/extensions/emoji/js/forum/src/addComposerAutocomplete.js +++ b/extensions/emoji/js/forum/src/addComposerAutocomplete.js @@ -51,8 +51,8 @@ export default function addComposerAutocomplete() { emojiStart = 0; for (let i = cursor - 1; i >= 0; i--) { const character = value.substr(i, 1); - if (/\s/.test(character)) break; - if (character === ':') { + if (!/[a-z0-9]|\+|\-|_|\:/.test(character)) break; + if (character === ':' && (i == 0 || value.substr(i-1, 1) === ' ')) { emojiStart = i + 1; break; } From 37efc0c6a799a86dc61dadb057f10e013e7bd4ee Mon Sep 17 00:00:00 2001 From: Sajjad Hasehmian Date: Mon, 15 Feb 2016 14:05:35 +0330 Subject: [PATCH 2/2] Update Autocomplete comments --- extensions/emoji/js/forum/dist/extension.js | 7 +++++-- extensions/emoji/js/forum/src/addComposerAutocomplete.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/emoji/js/forum/dist/extension.js b/extensions/emoji/js/forum/dist/extension.js index de0045cbb..b5a1ad921 100644 --- a/extensions/emoji/js/forum/dist/extension.js +++ b/extensions/emoji/js/forum/dist/extension.js @@ -176,14 +176,17 @@ 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); + // 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; diff --git a/extensions/emoji/js/forum/src/addComposerAutocomplete.js b/extensions/emoji/js/forum/src/addComposerAutocomplete.js index b878b3806..295d5584e 100644 --- a/extensions/emoji/js/forum/src/addComposerAutocomplete.js +++ b/extensions/emoji/js/forum/src/addComposerAutocomplete.js @@ -44,14 +44,17 @@ 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); + // 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;