Skip to content

Commit

Permalink
: and . registers implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
binny committed Mar 10, 2014
1 parent b16a1f2 commit 238015d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 14 additions & 2 deletions keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
var specialKeys = ['Left', 'Right', 'Up', 'Down', 'Space', 'Backspace',
'Esc', 'Home', 'End', 'PageUp', 'PageDown', 'Enter'];
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"','.',':']);

function isLine(cm, line) {
return line >= cm.firstLine() && line <= cm.lastLine();
Expand Down Expand Up @@ -797,6 +797,8 @@
function RegisterController(registers) {
this.registers = registers;
this.unnamedRegister = registers['"'] = new Register();
registers['.'] = new Register();
registers[':'] = new Register();
}
RegisterController.prototype = {
pushText: function(registerName, operator, text, linewise) {
Expand Down Expand Up @@ -3200,10 +3202,14 @@
Vim.ExCommandDispatcher.prototype = {
processCommand: function(cm, input) {
var vim = cm.state.vim;
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
var previousCommand = commandHistoryRegister.toString();
if (vim.visualMode) {
exitVisualMode(cm);
}
var inputStream = new CodeMirror.StringStream(input);
// update ": with the latest command whether valid or invalid
commandHistoryRegister.setText(inputStream.string);
var params = {};
params.input = input;
try {
Expand All @@ -3222,6 +3228,9 @@
var command = this.matchCommand_(params.commandName);
if (command) {
commandName = command.name;
if (commandName == 'registers') {
commandHistoryRegister.setText(previousCommand);
}
this.parseCommandArgs_(inputStream, params, command);
if (command.type == 'exToKey') {
// Handle Ex to Key mapping.
Expand Down Expand Up @@ -3513,7 +3522,7 @@
continue;
}
var register = registers[registerName] || new Register();
regInfo += '"' + registerName + ' ' + register.text + '<br>';
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
}
}
showConfirm(cm, regInfo);
Expand Down Expand Up @@ -3888,6 +3897,7 @@
function exitInsertMode(cm) {
var vim = cm.state.vim;
var macroModeState = vimGlobalState.macroModeState;
var imcRegister = vimGlobalState.registerController.getRegister('.');
var isPlaying = macroModeState.isPlaying;
if (!isPlaying) {
cm.off('change', onChange);
Expand All @@ -3906,6 +3916,8 @@
cm.setOption('keyMap', 'vim');
cm.setOption('disableInput', true);
cm.toggleOverwrite(false); // exit replace mode if we were in it.
// update the ". register before exiting insert mode
imcRegister.setText(macroModeState.lastInsertModeChanges.changes.join(''));
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
if (macroModeState.isRecording) {
logInsertModeChange(macroModeState);
Expand Down
13 changes: 13 additions & 0 deletions test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,19 @@ testVim('macro_register', function(cm, vim, helpers) {
});
helpers.doKeys(':');
}, { value: ''});
testVim('ro_registers', function(cm,vim,helpers) {
cm.setCursor(0,0);
helpers.doKeys('i');
cm.replaceRange('foo',cm.getCursor());
helpers.doInsertModeKeys('Esc');
helpers.doEx('sort');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/\.\s+foo/.test(text));
is(/:\s+sort/.test(text));
});
helpers.doKeys(':');
}, {value: ''});
testVim('.', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('2', 'd', 'w');
Expand Down

0 comments on commit 238015d

Please sign in to comment.