   # Save the selection, so performFindInPlace can restore it.
   findModeSaveSelection()
   window.findModeQuery = rawQuery: ""
-  findMode = new FindMode options
+  window.findMode = new FindMode options
   HUD.showFindMode()
   findMode
 

      exitOnClick: true

      keydown: (event) =>
        window.scrollTo @scrollX, @scrollY if options.returnToViewport
        if event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey
          HUD.hide()
          @exit()
          new PostFindMode if findModeQueryHasResults
        else if event.keyCode == keyCodes.enter
          handleEnterForFindMode()
          @exit()
          new PostFindMode if findModeQueryHasResults
        else if event.keyCode == keyCodes.upArrow
          if rawQuery = FindModeHistory.getQuery @historyIndex + 1
            @historyIndex += 1
            @partialQuery = findModeQuery.rawQuery if @historyIndex == 0
            HUD.showFindMode rawQuery
        else if event.keyCode == keyCodes.downArrow
          @historyIndex = Math.max -1, @historyIndex - 1
          rawQuery = if 0 <= @historyIndex then FindModeHistory.getQuery @historyIndex else @partialQuery
          HUD.showFindMode rawQuery
        else if KeyboardUtils.isEscape event
          @exit()
          handleEscapeForFindMode()
          new PostFindMode if findModeQueryHasResults


#

window.findModeQuery = { rawQuery: "", matchCount: 0 }
window.findMode = null
findModeQueryHasResults = false
findModeAnchorNode = null
findModeInitialRange = null
