Skip to content

Commit

Permalink
account for Ex dialog prompts in search queries recorded into macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
heppe committed Mar 10, 2014
1 parent b92c57c commit 2054ec8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
40 changes: 33 additions & 7 deletions keymap/vim.js
Expand Up @@ -537,6 +537,7 @@
this.latestRegister = undefined;
this.isPlaying = false;
this.isRecording = false;
this.replaySearchQueries = [];
this.onRecordingDone = undefined;
this.lastInsertModeChanges = createInsertModeChanges();
}
Expand Down Expand Up @@ -752,6 +753,7 @@
this.clear();
this.keyBuffer = [text || ''];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = !!linewise;
}
Register.prototype = {
Expand All @@ -770,9 +772,13 @@
pushInsertModeChanges: function(changes) {
this.insertModeChanges.push(createInsertModeChanges(changes));
},
pushSearchQuery: function(query) {
this.searchQueries.push(query);
},
clear: function() {
this.keyBuffer = [];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = false;
},
toString: function() {
Expand Down Expand Up @@ -1064,6 +1070,10 @@
function onPromptClose(query) {
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
logSearchQuery(macroModeState, query);
}
}
function onPromptKeyUp(_e, query) {
var parsedQuery;
Expand Down Expand Up @@ -1094,13 +1104,19 @@
}
switch (command.searchArgs.querySrc) {
case 'prompt':
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
var query = macroModeState.replaySearchQueries.shift();
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
} else {
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
}
break;
case 'wordUnderCursor':
var word = expandWordUnderCursor(cm, false /** inclusive */,
Expand Down Expand Up @@ -3922,6 +3938,7 @@
var keyBuffer = register.keyBuffer;
var imc = 0;
macroModeState.isPlaying = true;
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
for (var i = 0; i < keyBuffer.length; i++) {
var text = keyBuffer[i];
var match, key;
Expand Down Expand Up @@ -3960,6 +3977,15 @@
}
}

function logSearchQuery(macroModeState, query) {
if (macroModeState.isPlaying) { return; }
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.pushSearchQuery(query);
}
}

/**
* Listens for changes made in insert mode.
* Should only be active in insert mode.
Expand Down
26 changes: 24 additions & 2 deletions test/vim_test.js
Expand Up @@ -1770,7 +1770,7 @@ testVim('macro_t_search', function(cm, vim, helpers) {
helpers.assertCursorAt(0, 1);
helpers.doKeys('l', '@', 'a');
helpers.assertCursorAt(0, 6);
helpers.doKeys('l', '@', 'a');
helpers.doKeys('l', ';');
helpers.assertCursorAt(0, 12);
}, { value: 'one line of text.'});
testVim('macro_f_search', function(cm, vim, helpers) {
Expand All @@ -1779,9 +1779,31 @@ testVim('macro_f_search', function(cm, vim, helpers) {
helpers.assertCursorAt(0, 2);
helpers.doKeys('@', 'b');
helpers.assertCursorAt(0, 7);
helpers.doKeys('@', 'b');
helpers.doKeys(';');
helpers.assertCursorAt(0, 13);
}, { value: 'one line of text.'});
testVim('macro_slash_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'c');
cm.openDialog = helpers.fakeOpenDialog('e');
helpers.doKeys('/', 'q');
helpers.assertCursorAt(0, 2);
helpers.doKeys('@', 'c');
helpers.assertCursorAt(0, 7);
helpers.doKeys('n');
helpers.assertCursorAt(0, 13);
}, { value: 'one line of text.'});
testVim('macro_multislash_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'd');
cm.openDialog = helpers.fakeOpenDialog('e');
helpers.doKeys('/');
cm.openDialog = helpers.fakeOpenDialog('t');
helpers.doKeys('/', 'q');
helpers.assertCursorAt(0, 12);
helpers.doKeys('@', 'd');
helpers.assertCursorAt(0, 15);
}, { value: 'one line of text to rule them all.'});
testVim('macro_parens', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'z', 'i');
Expand Down

0 comments on commit 2054ec8

Please sign in to comment.