diff options
| author | Stephen Blott | 2015-10-24 05:59:49 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-10-24 05:59:49 +0100 | 
| commit | 6331f29edcc05d4a36a8cccb4d3f2c8eecc5dc03 (patch) | |
| tree | dc5c6f209a1855fe43f0b7940294d8b1951363b1 | |
| parent | ad53ad0b0b9a75825caf796ff65e091deb784e84 (diff) | |
| parent | 6dd120cf67b75b35c2fced66644fa4eae4c86764 (diff) | |
| download | vimium-6331f29edcc05d4a36a8cccb4d3f2c8eecc5dc03.tar.bz2 | |
Merge pull request #1865 from mrmr1993/visual-mode-range-getBoundingClientRects
Properly check whether the selection is visible in the current viewport
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 7 | ||||
| -rw-r--r-- | lib/rect.coffee | 4 | 
2 files changed, 9 insertions, 2 deletions
| diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index ce3caafe..9e597cca 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -484,8 +484,11 @@ class VisualMode extends Movement          @extendByOneCharacter(forward) or @extendByOneCharacter backward        else          if @selection.type in [ "Caret", "Range" ] -          elementWithFocus = DomUtils.getElementWithFocus @selection, @getDirection() == backward -          if DomUtils.getVisibleClientRect elementWithFocus +          selectionRect = @selection.getRangeAt(0).getBoundingClientRect() +          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"                # The caret is in the viewport. Make make it visible.                @extendByOneCharacter(forward) or @extendByOneCharacter backward diff --git a/lib/rect.coffee b/lib/rect.coffee index adc1fc36..0c67d287 100644 --- a/lib/rect.coffee +++ b/lib/rect.coffee @@ -78,5 +78,9 @@ Rect =        return false if rect1[property] != rect2[property]      true +  intersect: (rect1, rect2) -> +    @create (Math.max rect1.left, rect2.left), (Math.max rect1.top, rect2.top), +        (Math.min rect1.right, rect2.right), (Math.min rect1.bottom, rect2.bottom) +  root = exports ? window  root.Rect = Rect | 
