Skip to content

Commit

Permalink
feat(emit): $emit('at') on at trigger, ref #14, #16
Browse files Browse the repository at this point in the history
could be used for remote request
  • Loading branch information
fritx committed Sep 29, 2017
1 parent 522ad61 commit 1b95f75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/At.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export default {
},
atwho (val) {
this.$emit('has-at', !!val)
},
members () {
this.handleInput(true)
}
},
Expand Down Expand Up @@ -176,7 +179,7 @@ export default {
this.hasComposition = false
this.handleInput()
},
handleInput () {
handleInput (keep) {
if (this.hasComposition) return
const range = getPrecedingRange()
if (range) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -239,7 +245,7 @@ export default {
list,
x: rect.left,
y: rect.top - 4,
cur: 0, // todo: 尽可能记录
cur: 0 // todo: 尽可能记录
}
}
if (this.atwho) {
Expand Down
7 changes: 5 additions & 2 deletions src/AtTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
Expand Down

0 comments on commit 1b95f75

Please sign in to comment.