Skip to content

Commit

Permalink
[vim] add API for defining custom commands (codemirror#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Feb 18, 2015
1 parent 4ed39b1 commit 5047777
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,16 @@
},
handleEx: function(cm, input) {
exCommandDispatcher.processCommand(cm, input);
}
},

defineMotion: defineMotion,
defineAction: defineAction,
defineOperator: defineOperator,
mapCommand: mapCommand,
_mapCommand: _mapCommand,

exitVisualMode: exitVisualMode,
exitInsertMode: exitInsertMode
};

// Represents the current input state.
Expand Down Expand Up @@ -1817,6 +1826,10 @@
}
};

function defineMotion(name, fn) {
motions[name] = fn;
}

function fillArray(val, times) {
var arr = [];
for (var i = 0; i < times; i++) {
Expand Down Expand Up @@ -1967,6 +1980,10 @@
}
};

function defineOperator(name, fn) {
operators[name] = fn;
}

var actions = {
jumpListWalk: function(cm, actionArgs, vim) {
if (vim.visualMode) {
Expand Down Expand Up @@ -2478,6 +2495,10 @@
exitInsertMode: exitInsertMode
};

function defineAction(name, fn) {
actions[name] = fn;
}

/*
* Below are miscellaneous utility functions used by vim.js
*/
Expand Down Expand Up @@ -4632,6 +4653,19 @@
}
}

function _mapCommand(command) {
defaultKeymap.push(command);
}

function mapCommand(keys, type, name, args, extra) {
var command = {keys: keys, type: type};
command[type] = name;
command[type + "Args"] = args;
for (var key in extra)
command[key] = extra[key];
_mapCommand(command);
}

// The timeout in milliseconds for the two-character ESC keymap should be
// adjusted according to your typing speed to prevent false positives.
defineOption('insertModeEscKeysTimeout', 200, 'number');
Expand Down

0 comments on commit 5047777

Please sign in to comment.