diff --git a/lib/ace/commands/command_manager.js b/lib/ace/commands/command_manager.js index 5ba3f4cb..80626578 100644 --- a/lib/ace/commands/command_manager.js +++ b/lib/ace/commands/command_manager.js @@ -9,7 +9,7 @@ var CommandManager = function(platform, commands) { this.platform = platform; this.commands = {}; this.commmandKeyBinding = {}; - + if (commands) commands.forEach(this.addCommand, this); }; @@ -23,10 +23,10 @@ var CommandManager = function(platform, commands) { this.commands[command.name] = command; if (command.bindKey) { - this._buildKeyHash(command); + this._buildKeyHash(command); } }; - + this.removeCommand = function(command) { var name = (typeof command === 'string' ? command : command.name); command = this.commands[name]; @@ -51,7 +51,7 @@ var CommandManager = function(platform, commands) { if(!binding[this.platform]) { return; } - + key.split("|").forEach(function(keyPart) { var binding = parseKeys(keyPart, command); var hashId = binding.hashId; @@ -70,11 +70,11 @@ var CommandManager = function(platform, commands) { else key = parts[i] || "-"; //when empty, the splitSafe removed a '-' } - + return { key: key, hashId: hashId - } + } } function splitSafe(s, separator) { @@ -96,7 +96,7 @@ var CommandManager = function(platform, commands) { this.exec = function(command, editor, args) { if (typeof command === 'string') command = this.commands[command]; - + if (!command) return false; @@ -108,11 +108,14 @@ var CommandManager = function(platform, commands) { }; this.toggleRecording = function() { + if (this.$inReplay) + return; if (this.recording) { + this.macro.pop(); this.exec = this.normal_exec; return this.recording = false; } - this.macro = [] + this.macro = []; this.normal_exec = this.exec; this.exec = function(command, editor, args) { this.macro.push([command, args]); @@ -120,23 +123,37 @@ var CommandManager = function(platform, commands) { }; return this.recording = true; }; - - this.replay = function(editor){ - if (!this.macro) { - this.toggleRecording(); - return - } - if (this.recording) { - this.toggleRecording(); - this.macro.pop() + this.replay = function(editor) { + if (this.$inReplay) + return; + + if (!this.macro || this.recording) + return this.toggleRecording(); + + try { + this.$inReplay = true; + this.macro.forEach(function(x) { + if (typeof x == "string") + this.exec(x, editor); + else + this.exec(x[0], editor, x[1]); + }, this) + } finally { + this.$inReplay = false; } - - this.macro.forEach(function(x) { - this.exec(x[0], editor, x[1]); - }, this) }; + this.trimMacro = function(m) { + return m.map(function(x){ + if (typeof x[0] != "string") + x[0] = x[0].name; + if (!x[1]) + x = x[0]; + return x + }) + } + }).call(CommandManager.prototype); exports.CommandManager = CommandManager;