         @cachedItems = items if @provider.supportCacheItems
         items
 
-    filterSpec = getFilterSpecForQuery(@getQuery())
+    filterSpec = getFilterSpecForQuery(@lastQuery = @getQuery())
     if @provider.updateGrammarOnQueryChange
       @grammar.update(filterSpec.include) # No need to highlight excluded items
 

      @disposables.add @onDidMoveToItemArea =>
        @setReadOnly(true)

    @disposables.add(
      @registerCommands()
      @observeChange()
      @observeCursorMove()
      @observeStopChangingActivePaneItem()
    )
    # Depends on ui.grammar and commands bound to @editorElement, so have to come last
    @providerPanel = new ProviderPanel(this, showSearchOption: @provider.showSearchOption)

    @constructor.register(this)
    @disposables.add new Disposable =>
      @constructor.unregister(this)

  start: ->
    # When initial getItems() take very long time, it means refresh get delayed.
    # In this case, user see modified icon(mark) on tab.
    # Explicitly setting modified start here prevent this
    @setModifiedState(false)

    providerPane = @provider.getPane()
    if isNarrowEditor(@provider.editor)
      # If narrow is invoked from narrow-editor, open in same pane.
      pane = providerPane
    else
      pane = getAdjacentPaneOrSplit(providerPane, split: settings.get('directionToOpen'))

    pane.activate() unless pane.isActive()
    pane.activateItem(@editor, {@pending})

    @grammar.activate()
    if @query
      @insertQuery(@query)
    else
      @withIgnoreChange => @insertQuery()
    @providerPanel.show()
    @moveToPrompt()
    @refresh().then =>
      @activateProviderPane() unless @activate

  observeStopChangingActivePaneItem: ->
    atom.workspace.onDidStopChangingActivePaneItem (item) =>
      @provider.needRestoreEditorState = false
      return if not isTextEditor(item) or isNarrowEditor(item)
      return if paneForItem(item) is @getPane()
      @startSyncToEditor(item)

    @previewItemForDirection('previous')

  getQuery: ->
    @editor.lineTextForBufferRow(0)

  excludeFile: ->
    return if @provider.boundToEditor
