 
     # Establish or use the initial selection.  If that's not possible, then enter caret mode.
     unless @name == "caret"
-      if @selection.anchorNode?
+      if @selection.type in [ "Caret", "Range" ]
         selectionRect = @selection.getRangeAt(0).getBoundingClientRect()
         if window.vimiumDomTestsAreRunning
           # We're running the DOM tests, where getBoundingClientRect() isn't available.

      commandHandler: @commandHandler.bind this

    # If there was a range selection when the user lanuched visual mode, then we retain the selection on exit.
    @shouldRetainSelectionOnExit = @options.userLaunchedMode and 0 < @selection.toString().length

    @onExit (event = null) =>
      if @shouldRetainSelectionOnExit


  # Scroll the focus into view.
  scrollIntoView: ->
    unless @selection.type == "None"
      elementWithFocus = DomUtils.getElementWithFocus @selection, @getDirection() == backward
      Scroller.scrollIntoView elementWithFocus if elementWithFocus

