diff --git a/src/vim.js b/src/vim.js index 237858b..84d98d7 100644 --- a/src/vim.js +++ b/src/vim.js @@ -216,6 +216,8 @@ export function initVim(CM) { { keys: 'V', type: 'action', action: 'toggleVisualMode', actionArgs: { linewise: true }}, { keys: '', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }}, { keys: '', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }}, + { keys: '', type: 'action', action: 'toggleSelectMode', context: 'visual'}, + { keys: '', type: 'action', action: 'toggleSelectMode', context: 'insert'}, { keys: 'gv', type: 'action', action: 'reselectLastSelection' }, { keys: 'J', type: 'action', action: 'joinLines', isEdit: true }, { keys: 'gJ', type: 'action', action: 'joinLines', actionArgs: { keepSpaces: true }, isEdit: true }, @@ -3152,6 +3154,22 @@ export function initVim(CM) { exitVisualMode(cm); } }, + toggleSelectMode: function(cm, actionArgs, vim) { + const selections = cm.listSelections(); + const has_selection = selections.some( + (s) => s.anchor.line !== s.head.line || s.anchor.ch !== s.head.ch + ); + if (!has_selection) { + return; + } + if (vim.insertMode) { + exitInsertMode(cm); + cm.setSelections(selections); + } else if (vim.visualMode) { + this.enterInsertMode(cm, {repeat: actionArgs.repeat}, vim); + cm.setSelections(selections); + } + }, reselectLastSelection: function(cm, _actionArgs, vim) { var lastSelection = vim.lastSelection; if (vim.visualMode) {