     hideDocumentation: ->
         @documentation.hide()
 
-    getMaxIndex: ->
-        Math.min(maxItems, @suggestionsArr.length)
+    getMaxIndex: (length) ->
+        #Math.min(maxItems, @suggestionsArr.length)
+        Math.min(maxItems, length)
 
     addSelector: (selector) ->
         @selector = @selector + ',' + selector

            @clearSuggestions()
            @documentation.hide()
        @disposables.push @autocompletePlus.autocompleteManager.suggestionList.emitter.on 'did-select-next', =>
            if ++@currentSuggestionIndex >= @getMaxIndex()
                @currentSuggestionIndex = 0
            @setDocumentationContent()
        @disposables.push @autocompletePlus.autocompleteManager.suggestionList.emitter.on 'did-select-previous', =>
            if --@currentSuggestionIndex < 0
                @currentSuggestionIndex = @getMaxIndex() - 1
            @setDocumentationContent()

    unregisterEvents: ->
        for disposable in @disposables

                , (err) ->
                    console.log err

    setDocumentationContent: (length) ->
        return unless @suggestionsArr.length
        if @currentSuggestionIndex >= @suggestionsArr.length
            @hideDocumentation()
            return

        currentSuggestion = @suggestionsArr[@currentSuggestionIndex]
        if !currentSuggestion._ternDocs and !currentSuggestion._ternUrl and !currentSuggestion._ternOrigin
            @documentation.hide()
            return
        
        @documentation.set({
            word: currentSuggestion.word,
            label: currentSuggestion.label,
