properly handle replay/toggleRecording while in replay mode

This commit is contained in:
nightwing 2011-11-20 18:08:04 +04:00
commit 262df95a3d

View file

@ -108,11 +108,14 @@ var CommandManager = function(platform, commands) {
}; };
this.toggleRecording = function() { this.toggleRecording = function() {
if (this.$inReplay)
return;
if (this.recording) { if (this.recording) {
this.macro.pop();
this.exec = this.normal_exec; this.exec = this.normal_exec;
return this.recording = false; return this.recording = false;
} }
this.macro = [] this.macro = [];
this.normal_exec = this.exec; this.normal_exec = this.exec;
this.exec = function(command, editor, args) { this.exec = function(command, editor, args) {
this.macro.push([command, args]); this.macro.push([command, args]);
@ -121,22 +124,36 @@ var CommandManager = function(platform, commands) {
return this.recording = true; return this.recording = true;
}; };
this.replay = function(editor){ this.replay = function(editor) {
if (!this.macro) { if (this.$inReplay)
this.toggleRecording(); return;
return
}
if (this.recording) { if (!this.macro || this.recording)
this.toggleRecording(); return this.toggleRecording();
this.macro.pop()
}
this.macro.forEach(function(x) { try {
this.exec(x[0], editor, x[1]); this.$inReplay = true;
}, this) 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.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); }).call(CommandManager.prototype);
exports.CommandManager = CommandManager; exports.CommandManager = CommandManager;