From 6cff1b0dfccdb137e95e52c9a931fed14cec82d5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 31 Jan 2015 12:30:13 +0000 Subject: 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. --- content_scripts/mode_visual_edit.coffee | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'content_scripts') 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() -- cgit v1.2.3