diff options
| author | Stephen Blott | 2015-01-31 12:30:13 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-01-31 12:51:13 +0000 | 
| commit | 6cff1b0dfccdb137e95e52c9a931fed14cec82d5 (patch) | |
| tree | 453f8ce3f56cfd7315521ad807044407bb5eccba /content_scripts/mode_visual_edit.coffee | |
| parent | 70c7cb66e96305b0f8bbd8687fe8272d989ed3d9 (diff) | |
| download | vimium-6cff1b0dfccdb137e95e52c9a931fed14cec82d5.tar.bz2 | |
Visual/edit modes: change visual-mode start up...
When visual mode launches and there *is* a selection but it's outside of
the viewport, instead of scrolling it into view, ignore it, and start
with a visible caret.
Diffstat (limited to 'content_scripts/mode_visual_edit.coffee')
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 19 | 
1 files changed, 15 insertions, 4 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index a7abd314..d936ac1e 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -424,9 +424,20 @@ class VisualMode extends Movement        if @options.parentMode and @selection.type == "Caret"          # We're being called from edit mode, so establish an intial visible selection.          @extendByOneCharacter(forward) or @extendByOneCharacter backward -      else if @selection.type in [ "None", "Caret" ] -        unless @options.oneMovementOnly or options.immediateMovement -          HUD.showForDuration "No selection, entering caret mode first..", 2500 +      else +        if @selection.type in [ "Caret", "Range" ] +          elementWithFocus = DomUtils.getElementWithFocus @selection, @getDirection() == backward +          if DomUtils.getVisibleClientRect elementWithFocus +            if @selection.type == "Caret" +              # Make the selection visible. +              @extendByOneCharacter(forward) or @extendByOneCharacter backward +          else +            # If the selection is outside of the viewport, we clear it.  We guess that the user has moved on, +            # and is more likely to be interested in visible content. +            @selection.removeAllRanges() + +        if @selection.type != "Range" +          HUD.showForDuration "Entering caret mode first..", 2500            @changeMode CaretMode            return @@ -530,7 +541,7 @@ class CaretMode extends Movement            @exit()            return        when "Range" -        @collapseSelectionToFocus() +        @collapseSelectionToAnchor()      @selection.modify "extend", forward, character      @scrollIntoView()  | 
