diff options
| -rw-r--r-- | content_scripts/mode_visual.coffee | 14 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 4 | 
2 files changed, 11 insertions, 7 deletions
| diff --git a/content_scripts/mode_visual.coffee b/content_scripts/mode_visual.coffee index cc1baf34..28097005 100644 --- a/content_scripts/mode_visual.coffee +++ b/content_scripts/mode_visual.coffee @@ -159,7 +159,7 @@ class Movement    # Scroll the focus into view.    scrollIntoView: -> -    unless @selection.type == "None" +    unless DomUtils.getSelectionType(@selection) == "None"        elementWithFocus = DomUtils.getElementWithFocus @selection, @getDirection() == backward        Scroller.scrollIntoView elementWithFocus if elementWithFocus @@ -240,7 +240,7 @@ class VisualMode extends KeyHandlerMode        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 @selection.type == "Range" +    @shouldRetainSelectionOnExit = @options.userLaunchedMode and DomUtils.getSelectionType(@selection) == "Range"      @onExit (event = null) =>        if @shouldRetainSelectionOnExit @@ -269,7 +269,7 @@ class VisualMode extends KeyHandlerMode      # Establish or use the initial selection.  If that's not possible, then enter caret mode.      unless @name == "caret" -      if @selection.type in [ "Caret", "Range" ] +      if DomUtils.getSelectionType(@selection) in [ "Caret", "Range" ]          selectionRect = @selection.getRangeAt(0).getBoundingClientRect()          if window.vimiumDomTestsAreRunning            # We're running the DOM tests, where getBoundingClientRect() isn't available. @@ -277,7 +277,7 @@ class VisualMode extends KeyHandlerMode          selectionRect = Rect.intersect selectionRect, Rect.create 0, 0, window.innerWidth, window.innerHeight          if selectionRect.height >= 0 and selectionRect.width >= 0            # The selection is visible in the current viewport. -          if @selection.type == "Caret" +          if DomUtils.getSelectionType(@selection) == "Caret"              # The caret is in the viewport. Make make it visible.              @movement.extendByOneCharacter(forward) or @movement.extendByOneCharacter backward          else @@ -285,7 +285,7 @@ class VisualMode extends KeyHandlerMode            # more likely to be interested in visible content.            @selection.removeAllRanges() -      if @selection.type != "Range" and @name != "caret" +      if DomUtils.getSelectionType(@selection) != "Range" and @name != "caret"          new CaretMode          HUD.showForDuration "No usable selection, entering caret mode...", 2500 @@ -341,10 +341,10 @@ class CaretMode extends VisualMode      super extend options, name: "caret", indicator: "Caret mode", alterMethod: "move"      # Establish the initial caret. -    switch @selection.type +    switch DomUtils.getSelectionType(@selection)        when "None"          @establishInitialSelectionAnchor() -        if @selection.type == "None" +        if DomUtils.getSelectionType(@selection) == "None"            @exit()            HUD.showForDuration "Create a selection before entering visual mode.", 2500            return diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 06db1b9b..8fdc319e 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -326,6 +326,10 @@ DomUtils =        @suppressEvent event        handlerStack.suppressEvent + +  getSelectionType: (selection) -> +    selection.type +    # Adapted from: http://roysharon.com/blog/37.    # This finds the element containing the selection focus.    getElementWithFocus: (selection, backwards) -> | 
