fix bug in unapply for batch command

master
JFH 2020-07-25 19:33:44 +02:00
parent 61b4a4accb
commit 48212c8384
2 changed files with 20 additions and 13 deletions

View File

@ -20,11 +20,17 @@ describe('history', function () {
// const svg = document.createElementNS(NS.SVG, 'svg');
let undoMgr = null;
class MockCommand {
constructor (optText) { this.text_ = optText; }
apply () { /* */ } // eslint-disable-line class-methods-use-this
unapply () { /* */ } // eslint-disable-line class-methods-use-this
getText () { return this.text_; }
class MockCommand extends hstory.Command {
constructor (optText) {
super();
this.text = optText;
}
apply (handler) {
super.apply(handler, () => { /* */ });
}
unapply (handler) {
super.unapply(handler, () => { /* */ });
}
elements () { return []; } // eslint-disable-line class-methods-use-this
}
@ -482,17 +488,17 @@ describe('history', function () {
it('Test BatchCommand', function () {
let concatResult = '';
MockCommand.prototype.apply = function () { concatResult += this.text_; };
MockCommand.prototype.apply = function (handler) { concatResult += this.text; };
const batch = new hstory.BatchCommand();
assert.ok(batch.unapply);
assert.ok(batch.apply);
assert.ok(batch.addSubCommand);
assert.ok(batch.isEmpty);
assert.equal(typeof batch.unapply, typeof function () { /* */ });
assert.equal(typeof batch.apply, typeof function () { /* */ });
assert.equal(typeof batch.addSubCommand, typeof function () { /* */ });
assert.equal(typeof batch.isEmpty, typeof function () { /* */ });
assert.equal(typeof batch.unapply, 'function');
assert.equal(typeof batch.apply, 'function');
assert.equal(typeof batch.addSubCommand, 'function');
assert.equal(typeof batch.isEmpty, 'function');
assert.ok(batch.isEmpty());
@ -506,8 +512,9 @@ describe('history', function () {
assert.equal(concatResult, 'abc');
MockCommand.prototype.apply = function () { /* */ };
MockCommand.prototype.unapply = function () { concatResult += this.text_; };
MockCommand.prototype.unapply = function () { concatResult += this.text; };
concatResult = '';
assert.ok(!concatResult);
batch.unapply();
assert.equal(concatResult, 'cba');

View File

@ -22,7 +22,7 @@ export const HistoryEventTypes = {
/**
* Base class for commands.
*/
class Command {
export class Command {
/**
* @returns {string}
*/
@ -434,7 +434,7 @@ export class BatchCommand extends Command {
*/
unapply (handler) {
super.unapply(handler, () => {
this.stack.forEach((stackItem) => {
this.stack.reverse().forEach((stackItem) => {
console.assert(stackItem, 'stack item should not be null');
stackItem && stackItem.unapply(handler);
});