leo-buneev / vuepress-plugin-fulltext-search

Adds full-text search capabilities to your vuepress site with a help of flexsearch library.
MIT License
93 stars 23 forks source link

[BUG] Error in v-on handler: "TypeError: Cannot read property 'external' of undefined" #32

Closed Red-Asuka closed 2 years ago

Red-Asuka commented 3 years ago

when i mouse leave and keyup enter ,focusIndex = -1,this.suggestions[i].external is undefined, it can not jump.

unfocus() {
    this.focusIndex = -1
},

showSuggestions() {
    return this.focused && this.suggestions && this.suggestions.length
},

go(i) {
      if (!this.showSuggestions) {
        return
      }
      if (hooks.onGoToSuggestion) {
        const result = hooks.onGoToSuggestion(i, this.suggestions[i], this.query, this.queryTerms)
        if (result === true) return
      }
      if (this.suggestions[i].external) {
        window.open(this.suggestions[i].path + this.suggestions[i].slug, '_blank')
      } else {
        this.$router.push(this.suggestions[i].path + this.suggestions[i].slug)
        this.query = ''
        this.focusIndex = 0
        this.focused = false

        // reset query param
        const params = this.urlParams()
        if (params) {
          params.delete('query')
          const paramsString = params.toString()
          const newState = window.location.pathname + (paramsString ? `?${paramsString}` : '')
          history.pushState(null, '', newState)
        }
      }
    },

when i use keyup enter to jump, this.focused = false, but cursor is still focused, change query, it can not show Suggestions,because this.focused = false,showSuggestions = false,I don’t think there should be this.focused = false