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() {
|
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]);
|
||||||
|
|
@ -122,21 +125,35 @@ var CommandManager = function(platform, commands) {
|
||||||
};
|
};
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.$inReplay = true;
|
||||||
this.macro.forEach(function(x) {
|
this.macro.forEach(function(x) {
|
||||||
|
if (typeof x == "string")
|
||||||
|
this.exec(x, editor);
|
||||||
|
else
|
||||||
this.exec(x[0], editor, x[1]);
|
this.exec(x[0], editor, x[1]);
|
||||||
}, this)
|
}, 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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue