Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/codemirror-vim-core/test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,18 @@ testVim('reselect_visual_line', function(cm, vim, helpers) {
helpers.doKeys('V', 'p' , 'g', 'v', 'd');
eq('foo\nand', cm.getValue());
}, { value: 'hello\nthis\nis\nfoo\nand\nbar' });
testVim('reselect_visual_line_after_esc', function(cm, vim, helpers) {
helpers.doKeys('l', 'V', 'j', '<Esc>', 'g', 'v');
eq(vim.visualLine, true);
helpers.doKeys('d');
eq('is\nfoo', cm.getValue());
}, { value: 'hello\nthis\nis\nfoo' });
testVim('reselect_visual_block_after_esc', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>', 'j', 'l', '<Esc>', 'g', 'v');
eq(vim.visualBlock, true);
eq(cm.getSelections().join(''), '23oo');
}, { value: '123456\nfoo\nbar' });
testVim('reselect_visual_block', function(cm, vim, helpers) {
cm.setCursor(1, 2);
helpers.doKeys('<C-v>', 'k', 'h', '<C-v>');
Expand Down
6 changes: 6 additions & 0 deletions packages/codemirror-vim-core/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3958,6 +3958,12 @@ export function initVim(CM) {
if (moveHead !== false) {
cm.setCursor(clipCursorToContent(cm, vim.sel.head));
}
// Outside a vim operation (a typed <Esc> exits from handleEsc in findKey),
// the cursor move above reports cursor activity, and
// handleExternalSelection exits visual mode itself, recording the last
// selection with its linewise/blockwise flags. Recording it again here,
// after those flags were cleared, would make `gv` reselect charwise.
if (!vim.visualMode) return;
updateLastSelection(cm, vim);
vim.visualMode = false;
vim.visualLine = false;
Expand Down