Skip to content

Commit c3d3d47

Browse files
nightwingmarijnh
authored andcommitted
[vim] add support for guu
1 parent ceb65a6 commit c3d3d47

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

keymap/vim.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,12 @@
951951
if (!keysMatcher) { clearInputState(cm); return false; }
952952
var context = vim.visualMode ? 'visual' :
953953
'normal';
954-
var match = commandDispatcher.matchCommand(keysMatcher[2] || keysMatcher[1], defaultKeymap, vim.inputState, context);
954+
var mainKey = keysMatcher[2] || keysMatcher[1];
955+
if (vim.inputState.operatorShortcut && vim.inputState.operatorShortcut.slice(-1) == mainKey) {
956+
// multikey operators act linewise by repeating only the last character
957+
mainKey = vim.inputState.operatorShortcut;
958+
}
959+
var match = commandDispatcher.matchCommand(mainKey, defaultKeymap, vim.inputState, context);
955960
if (match.type == 'none') { clearInputState(cm); return false; }
956961
else if (match.type == 'partial') { return true; }
957962

@@ -1311,6 +1316,9 @@
13111316
}
13121317
inputState.operator = command.operator;
13131318
inputState.operatorArgs = copyArgs(command.operatorArgs);
1319+
if (command.keys.length > 1) {
1320+
inputState.operatorShortcut = command.keys;
1321+
}
13141322
if (command.exitVisualBlock) {
13151323
vim.visualBlock = false;
13161324
updateCmSelection(cm);

test/vim_test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,12 +1232,19 @@ testVim('gu_and_gU', function(cm, vim, helpers) {
12321232
eq(cm.getValue(), 'wa wb Xx wc wd');
12331233
eqCursorPos(makeCursor(0, 3), cm.getCursor());
12341234

1235-
// TODO: support gUgU guu
1236-
// eqCursorPos(makeCursor(0, 0), cm.getCursor());
1237-
12381235
var register = helpers.getRegisterController().getRegister();
12391236
eq('', register.toString());
12401237
is(!register.linewise);
1238+
1239+
cm.setCursor(curStart);
1240+
cm.setValue('abc efg\nxyz');
1241+
helpers.doKeys('g', 'U', 'g', 'U');
1242+
eq(cm.getValue(), 'ABC EFG\nxyz');
1243+
helpers.doKeys('g', 'u', 'u');
1244+
eq(cm.getValue(), 'abc efg\nxyz');
1245+
eqCursorPos(makeCursor(0, 0), cm.getCursor());
1246+
helpers.doKeys('g', 'U', '2', 'U');
1247+
eq(cm.getValue(), 'ABC EFG\nXYZ');
12411248
}, { value: 'wa wb xx wc wd' });
12421249
testVim('visual_block_~', function(cm, vim, helpers) {
12431250
cm.setCursor(1, 1);

0 commit comments

Comments
 (0)