diff options
| author | Stephen Blott | 2017-04-22 07:13:05 +0100 |
|---|---|---|
| committer | Stephen Blott | 2017-04-22 07:13:05 +0100 |
| commit | 961f7130a60ae041fb0304353160d6fc74529aa7 (patch) | |
| tree | a36c6b3b4538df695a66e811aec23e9672cc16e1 | |
| parent | 3296e8355280e10a8a96fcc7d03cc6bdc55fea54 (diff) | |
| download | vimium-961f7130a60ae041fb0304353160d6fc74529aa7.tar.bz2 | |
Revert "Firefox: Fix visual mode."
This reverts commit 50b117733c4f0ecf9fd507c28d2f2967b5b1404b.
Reverting this. In response to comments from @mrmr1993, this is not the
best way of achieving what's required.
| -rw-r--r-- | content_scripts/mode_visual.coffee | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/content_scripts/mode_visual.coffee b/content_scripts/mode_visual.coffee index 290fc1f4..cc1baf34 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: -> - if @selection.anchorNode + unless @selection.type == "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 0 < @selection.toString().length + @shouldRetainSelectionOnExit = @options.userLaunchedMode and @selection.type == "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.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. @@ -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.toString().length == 0 + if @selection.type == "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() - unless @selection.anchorNode + if @selection.type != "Range" and @name != "caret" new CaretMode HUD.showForDuration "No usable selection, entering caret mode...", 2500 @@ -341,14 +341,15 @@ class CaretMode extends VisualMode super extend options, name: "caret", indicator: "Caret mode", alterMethod: "move" # Establish the initial caret. - if @selection.anchorNode - @movement.collapseSelectionToAnchor() - else - @establishInitialSelectionAnchor() - unless @selection.anchorNode - @exit() - HUD.showForDuration "Create a selection before entering visual mode.", 2500 - return + switch @selection.type + when "None" + @establishInitialSelectionAnchor() + if @selection.type == "None" + @exit() + HUD.showForDuration "Create a selection before entering visual mode.", 2500 + return + when "Range" + @movement.collapseSelectionToAnchor() @movement.extendByOneCharacter forward @movement.scrollIntoView() |
