From 6dd120cf67b75b35c2fced66644fa4eae4c86764 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Fri, 23 Oct 2015 18:02:10 +0100 Subject: Properly check whether the selection is visible in the current viewport --- content_scripts/mode_visual_edit.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'content_scripts') 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 -- cgit v1.2.3