From 598f6fa4ffa1348c096ad681a10bee28adde4a3e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 11 Apr 2016 07:02:29 +0100 Subject: Better visual-mode selection handling. Assume there is an existing range selection. Consider `v`, `Escape`. Previously, this had the side effect of clearing the selection. That behaviour seems odd and wrong. Here, we retain the selection if there was an existing range selection when visual mode was launched. Arguably, this removes a "feature" whereby `v`, `Escape` clears the selection. Here, we take it that the oddity above outweighs the loss of this arguably unintentional "feature". --- content_scripts/mode_visual.coffee | 7 ++++++- content_scripts/vimium_frontend.coffee | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/content_scripts/mode_visual.coffee b/content_scripts/mode_visual.coffee index 011d6775..8c1fb5a4 100644 --- a/content_scripts/mode_visual.coffee +++ b/content_scripts/mode_visual.coffee @@ -235,9 +235,14 @@ class VisualMode extends KeyHandlerMode keyMapping: keyMapping commandHandler: @commandHandler.bind this + # If there was a range selection when the user lanuched visual mode, then we retain the selection on exit. + @shouldRetainSelectionOnExit = @options.userLaunchedMode and @selection.type == "Range" + @onExit (event = null) => + if @shouldRetainSelectionOnExit + null # Retain any selection, regardless of how we exit. # This mimics vim: when leaving visual mode via Escape, collapse to focus, otherwise collapse to anchor. - if event?.type == "keydown" and KeyboardUtils.isEscape(event) and @name != "caret" + else if event?.type == "keydown" and KeyboardUtils.isEscape(event) and @name != "caret" @movement.collapseSelectionToFocus() else @movement.collapseSelectionToAnchor() diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 6fb30dec..4dcdfe7d 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -358,10 +358,10 @@ extend window, new InsertMode global: true, exitOnFocus: true enterVisualMode: -> - new VisualMode() + new VisualMode userLaunchedMode: true enterVisualLineMode: -> - new VisualLineMode + new VisualLineMod userLaunchedMode: true passNextKey: (count) -> new PassNextKeyMode count -- cgit v1.2.3