properly handle replay/toggleRecording while in replay mode
This commit is contained in:
parent
52ea224893
commit
262df95a3d
1 changed files with 38 additions and 21 deletions
|
|
@ -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]);
|
||||
|
|
@ -121,22 +124,36 @@ var CommandManager = function(platform, commands) {
|
|||
return this.recording = true;
|
||||
};
|
||||
|
||||
this.replay = function(editor){
|
||||
if (!this.macro) {
|
||||
this.toggleRecording();
|
||||
return
|
||||
}
|
||||
this.replay = function(editor) {
|
||||
if (this.$inReplay)
|
||||
return;
|
||||
|
||||
if (this.recording) {
|
||||
this.toggleRecording();
|
||||
this.macro.pop()
|
||||
}
|
||||
if (!this.macro || this.recording)
|
||||
return this.toggleRecording();
|
||||
|
||||
this.macro.forEach(function(x) {
|
||||
this.exec(x[0], editor, x[1]);
|
||||
}, this)
|
||||
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.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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue