diff --git a/lib/ace/commands/command_manager.js b/lib/ace/commands/command_manager.js index 0e39ffe3..5ba3f4cb 100644 --- a/lib/ace/commands/command_manager.js +++ b/lib/ace/commands/command_manager.js @@ -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; diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index df11cf47..b898ef80 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -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