diff --git a/client/src/builtin/EmoteAc.js b/client/src/builtin/EmoteAc.js index 7ec3a05e..27c762ba 100644 --- a/client/src/builtin/EmoteAc.js +++ b/client/src/builtin/EmoteAc.js @@ -63,4 +63,10 @@ export default new class EmoteAc extends BuiltinModule { } } + toggle(sterm) { + if (sterm.length > 1) return false; + + return true; + } + } diff --git a/client/src/ui/autocomplete.js b/client/src/ui/autocomplete.js index 3745c0f6..b6e9fae7 100644 --- a/client/src/ui/autocomplete.js +++ b/client/src/ui/autocomplete.js @@ -44,6 +44,11 @@ export default new class AutoComplete { return this.sets.hasOwnProperty(prefix); } + toggle(prefix, sterm) { + if (!this.sets[prefix].toggle) return false; + return this.sets[prefix].toggle(sterm); + } + items(prefix, sterm) { if (!this.validPrefix(prefix)) return []; return this.sets[prefix].acsearch(sterm); diff --git a/client/src/ui/components/common/Autocomplete.vue b/client/src/ui/components/common/Autocomplete.vue index 68e6d112..52a80919 100644 --- a/client/src/ui/components/common/Autocomplete.vue +++ b/client/src/ui/components/common/Autocomplete.vue @@ -66,7 +66,9 @@ const { which, key } = e; if (key === 'ArrowDown' || key === 'ArrowUp') this.traverse(key); - else if (key !== 'Tab' && key !== 'Enter') return; + else if (key === 'ArrowLeft' || key === 'ArrowRight') { + if (!this.toggle(e)) return; + } else if (key !== 'Tab' && key !== 'Enter') return; e.stopPropagation(); e.preventDefault(); @@ -119,6 +121,12 @@ this.insertText(this.ta.selectionStart - this.fsterm.length, this.search.items[this.selectedIndex].value.replaceWith); this.open = false; this.search = { type: null, items: [] }; + }, + toggle(e) { + const { selectionEnd, value } = e.target; + const sterm = value.slice(0, selectionEnd).split(/\s+/g).pop(); + const prefix = sterm.slice(0, 1); + return this.controller.toggle(prefix, sterm); } } }