Skip to content

Commit a86e858

Browse files
nightwingmarijnh
authored andcommitted
[vim] fix blockwise yank
1 parent 1b3c322 commit a86e858

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

keymap/vim.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,17 @@
25702570
}
25712571
var linewise = register.linewise;
25722572
var blockwise = register.blockwise;
2573-
if (linewise) {
2573+
if (blockwise) {
2574+
text = text.split('\n');
2575+
if (linewise) {
2576+
text.pop();
2577+
}
2578+
for (var i = 0; i < text.length; i++) {
2579+
text[i] = (text[i] == '') ? ' ' : text[i];
2580+
}
2581+
cur.ch += actionArgs.after ? 1 : 0;
2582+
cur.ch = Math.min(lineLength(cm, cur.line), cur.ch);
2583+
} else if (linewise) {
25742584
if(vim.visualMode) {
25752585
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
25762586
} else if (actionArgs.after) {
@@ -2582,12 +2592,6 @@
25822592
cur.ch = 0;
25832593
}
25842594
} else {
2585-
if (blockwise) {
2586-
text = text.split('\n');
2587-
for (var i = 0; i < text.length; i++) {
2588-
text[i] = (text[i] == '') ? ' ' : text[i];
2589-
}
2590-
}
25912595
cur.ch += actionArgs.after ? 1 : 0;
25922596
}
25932597
var curPosFinal;

test/vim_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,21 @@ testVim('Y', function(cm, vim, helpers) {
14281428
is(register.linewise);
14291429
helpers.assertCursorAt(0, 3);
14301430
}, { value: ' word1\nword2\n word3' });
1431+
testVim('Yy_blockwise', function(cm, vim, helpers) {
1432+
helpers.doKeys('<C-v>', 'j', '2', 'l', 'Y');
1433+
helpers.doKeys('G', 'p', 'g', 'g');
1434+
helpers.doKeys('<C-v>', 'j', '2', 'l', 'y');
1435+
helpers.assertCursorAt(0, 0);
1436+
helpers.doKeys('$', 'p');
1437+
eq('123456123\n123456123\n123456\n123456', cm.getValue());
1438+
var register = helpers.getRegisterController().getRegister();
1439+
eq('123\n123', register.toString());
1440+
is(register.blockwise);
1441+
helpers.assertCursorAt(0, 6);
1442+
helpers.doKeys('$', 'j', 'p');
1443+
helpers.doKeys('$', 'j', 'P');
1444+
eq("123456123\n123456123123\n123456 121233\n123456 123", cm.getValue());
1445+
}, { value: '123456\n123456\n' });
14311446
testVim('~', function(cm, vim, helpers) {
14321447
helpers.doKeys('3', '~');
14331448
eq('ABCdefg', cm.getValue());

0 commit comments

Comments
 (0)