add simple keyboard macros

This commit is contained in:
nightwing 2011-11-19 21:52:13 +04:00
commit 0ba3333971
2 changed files with 40 additions and 0 deletions

View file

@ -107,6 +107,36 @@ var CommandManager = function(platform, commands) {
return true;
};
this.toggleRecording = function() {
if (this.recording) {
this.exec = this.normal_exec;
return this.recording = false;
}
this.macro = []
this.normal_exec = this.exec;
this.exec = function(command, editor, args) {
this.macro.push([command, args]);
return this.normal_exec(command, editor, args);
};
return this.recording = true;
};
this.replay = function(editor){
if (!this.macro) {
this.toggleRecording();
return
}
if (this.recording) {
this.toggleRecording();
this.macro.pop()
}
this.macro.forEach(function(x) {
this.exec(x[0], editor, x[1]);
}, this)
};
}).call(CommandManager.prototype);
exports.CommandManager = CommandManager;

View file

@ -252,6 +252,16 @@ exports.commands = [{
bindKey: bindKey("Shift-End", "Shift-End"),
exec: function(editor) { editor.getSelection().selectLineEnd(); },
readOnly: true
}, {
name: "togglerecording",
bindKey: bindKey("Ctrl-Shift-E", "Ctrl-Shift-E"),
exec: function(editor) { editor.commands.toggleRecording(); },
readOnly: true
}, {
name: "replaymacro",
bindKey: bindKey("Ctrl-E", "Ctrl-E"),
exec: function(editor) { editor.commands.replay(editor); },
readOnly: true
},
// commands disabled in readOnly mode