Skip to content

Commit

Permalink
feat: add replaceWith param to apply event (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
  • Loading branch information
Michaelvilleneuve and Akryum authored Dec 8, 2021
1 parent 6404052 commit 62e5f24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default {
onOpen (key) {
this.items = key === '@' ? users : issues
},
onApply (item, key, replacedWith) {
console.log(item, `has been replaced with ${replacedWith}`)
}
},
}
</script>
Expand All @@ -84,6 +88,7 @@ export default {
offset="6"
insert-space
@open="onOpen"
@apply="onApply"
>
<textarea
v-model="text"
Expand Down
8 changes: 6 additions & 2 deletions packages/test-e2e/src/views/Events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
@search="searchText = $event"
@open="openKey = $event"
@close="closeKey = $event"
@apply="(item, key) => applyEvent = { item, key }"
@apply="(item, key, replacedWith) => applyEvent = { item, key, replacedWith }"
>
<textarea
v-model="text"
Expand All @@ -48,6 +48,10 @@ export default {
<div class="search">{{ searchText }}</div>
<div class="open">{{ openKey }}</div>
<div class="close">{{ closeKey }}</div>
<div class="apply">value: {{ applyEvent ? applyEvent.item.value : null }} key: {{ applyEvent ? applyEvent.key : null }}</div>
<div class="apply">
value: {{ applyEvent ? applyEvent.item.value : null }}
key: {{ applyEvent ? applyEvent.key : null }}
replacedWith: {{ applyEvent ? applyEvent.replacedWith : null }}
</div>
</div>
</template>
1 change: 1 addition & 0 deletions packages/test-e2e/tests/e2e/specs/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ describe('events', () => {
cy.get('.input').type('{downArrow}{enter}')
cy.get('.apply').should('contain', 'value: posva')
.should('contain', 'key: @')
.should('contain', 'replacedWith: @posva')
})
})
2 changes: 1 addition & 1 deletion packages/vue-mention/src/Mentionable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export default {
this.setValue(this.replaceText(this.getValue(), this.searchText, value, this.keyIndex))
this.setCaretPosition(this.keyIndex + value.length)
}
this.$emit('apply', item, this.key)
this.$emit('apply', item, this.key, value)
this.closeMenu()
},
Expand Down

0 comments on commit 62e5f24

Please sign in to comment.