       @setLink(selection, "", "")
 
   updateSearch: ->
-    return unless @posts
     query = @searchEditor.getText().trim().toLowerCase()
-    results = @posts.filter (post) ->
+    results = posts.filter (post) ->
       query and post.title.toLowerCase().contains(query)
     results = results.map (post) ->
       "<li data-url='#{post.url}'>#{post.title}</li>"

    @on "core:cancel", => @detach()

  handleEvents: ->
    @searchEditor.hiddenInput.on "keyup", => @updateSearch()
    @searchResult.on "click", "li", (e) => @useSearchResult(e)

  onConfirm: ->

    atom.project.resolve(atom.config.get("markdown-writer.siteLinkPath"))

  fetchPosts: ->
    if posts
      @searchBox.show() if posts.length > 0
    else
      uri = atom.config.get("markdown-writer.urlForPosts")
      succeed = (body) =>
        posts = body.posts
        @searchBox.show() if posts.length > 0
      error = (err) =>
        @searchBox.hide()
      utils.getJSON(uri, succeed, error)
