diff options
| author | Stephen Blott | 2016-04-11 07:02:29 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-11 07:02:32 +0100 |
| commit | 598f6fa4ffa1348c096ad681a10bee28adde4a3e (patch) | |
| tree | 551c949a4d675c4ecaa077c280e0bf5d76ee8303 | |
| parent | ad2ed18dff81297f43ea89331ba227c26aed654a (diff) | |
| download | vimium-598f6fa4ffa1348c096ad681a10bee28adde4a3e.tar.bz2 | |
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".
| -rw-r--r-- | content_scripts/mode_visual.coffee | 7 | ||||
| -rw-r--r-- | 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 |
