diff options
| -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 |
