add simple keyboard macros
This commit is contained in:
parent
d926ff88a9
commit
0ba3333971
2 changed files with 40 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue