Skip to content

Commit

Permalink
fix: disable popover when input is email & enale popover when previou…
Browse files Browse the repository at this point in the history
…s input is space or new line (#12)

* fix: disable popover when input is email & enale popover when previous input is space or new line

* fix: simplify regex

* test(e2e): uncomment

Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
  • Loading branch information
taiyop and Akryum authored Dec 28, 2020
1 parent 0707e19 commit 17f7e52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/test-e2e/tests/e2e/specs/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,20 @@ describe('with default props', () => {
cy.get('.input').type('@{enter}abc')
cy.get('.preview').should('contain', '@akryumabc')
})

it('show suggestion when previous input is space', () => {
cy.visit('/defaults')
cy.get('.input').type(' @zzz')
cy.get('.popover').should('be.visible')
cy.get('.input').type(' @zzz')
cy.get('.popover').should('be.visible')
cy.get('.input').type('\n@zzz')
cy.get('.popover').should('be.visible')
})

it('does not show suggestion when text is email address', () => {
cy.visit('/defaults')
cy.get('.input').type('aaa@zzz.com')
cy.get('.popover').should('not.exist')
})
})
3 changes: 3 additions & 0 deletions packages/vue-mention/src/Mentionable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ export default {
if (index >= 0) {
const { key, keyIndex } = this.getLastKeyBeforeCaret(index)
const searchText = this.getLastSearchText(index, keyIndex)
if (!(keyIndex < 1 || /\s/.test(this.getValue()[keyIndex - 1]))) {
return false
}
if (searchText != null) {
this.openMenu(key, keyIndex)
this.searchText = searchText
Expand Down

0 comments on commit 17f7e52

Please sign in to comment.