From 1b95f75707825c8c93f46aaa9e8bc046c15d7e25 Mon Sep 17 00:00:00 2001 From: Fritz Lin Date: Fri, 29 Sep 2017 00:43:02 +0800 Subject: [PATCH] feat(emit): $emit('at') on at trigger, ref #14, #16 could be used for remote request --- src/At.vue | 10 ++++++++-- src/AtTextarea.vue | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/At.vue b/src/At.vue index fb1ab01..e3909eb 100644 --- a/src/At.vue +++ b/src/At.vue @@ -89,6 +89,9 @@ export default { }, atwho (val) { this.$emit('has-at', !!val) + }, + members () { + this.handleInput(true) } }, @@ -176,7 +179,7 @@ export default { this.hasComposition = false this.handleInput() }, - handleInput () { + handleInput (keep) { if (this.hasComposition) return const range = getPrecedingRange() if (range) { @@ -209,6 +212,9 @@ export default { this.closePanel() } else { const { members, filterMatch, itemName } = this + if (!keep) { + this.$emit('at', chunk) + } const matched = members.filter(v => { const name = itemName(v) return filterMatch(name, chunk, at) @@ -239,7 +245,7 @@ export default { list, x: rect.left, y: rect.top - 4, - cur: 0, // todo: 尽可能记录 + cur: 0 // todo: 尽可能记录 } } if (this.atwho) { diff --git a/src/AtTextarea.vue b/src/AtTextarea.vue index 84c4416..aa66ba0 100644 --- a/src/AtTextarea.vue +++ b/src/AtTextarea.vue @@ -45,7 +45,7 @@ export default { } }, - handleInput () { + handleInput (keep) { if (this.hasComposition) return const el = this.$el.querySelector('textarea') const text = el.value.slice(0, el.selectionEnd) @@ -71,12 +71,15 @@ export default { this.closePanel() } else { const { members, filterMatch, itemName } = this + if (!keep) { + this.$emit('at', chunk) + } const matched = members.filter(v => { const name = itemName(v) return filterMatch(name, chunk, at) }) if (matched.length) { - this.openPanel(matched, chunk, index, at) + this.openPanel(matched, chunk, index, at, keep) } else { this.closePanel() }