fix bug in unapply for batch command

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

View File

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