Include difference in history change events

This commit is contained in:
John Firebaugh
2012-12-07 12:29:17 -05:00
parent ea4b93d88b
commit c5c65ccdfd
2 changed files with 22 additions and 12 deletions

View File

@@ -19,10 +19,8 @@ iD.History = function() {
return {graph: graph, annotation: annotation};
}
function maybeChange() {
if (stack[index].annotation) {
dispatch.change();
}
function change(previous) {
dispatch.change(history.graph().difference(previous));
}
var history = {
@@ -37,32 +35,44 @@ iD.History = function() {
},
perform: function () {
var previous = stack[index].graph;
stack = stack.slice(0, index + 1);
stack.push(perform(arguments));
index++;
dispatch.change();
change(previous);
},
replace: function () {
var previous = stack[index].graph;
// assert(index == stack.length - 1)
stack[index] = perform(arguments);
dispatch.change();
change(previous);
},
undo: function () {
var previous = stack[index].graph;
while (index > 0) {
index--;
if (stack[index].annotation) break;
}
dispatch.change();
change(previous);
},
redo: function () {
var previous = stack[index].graph;
while (index < stack.length - 1) {
index++;
if (stack[index].annotation) break;
}
dispatch.change();
change(previous);
},
undoAnnotation: function () {

View File

@@ -28,7 +28,7 @@ describe("iD.History", function () {
it("emits a change event", function () {
history.on('change', spy);
history.perform(action);
expect(spy).to.have.been.called;
expect(spy).to.have.been.calledWith([]);
});
it("performs multiple actions", function () {
@@ -57,7 +57,7 @@ describe("iD.History", function () {
it("emits a change event", function () {
history.on('change', spy);
history.replace(action);
expect(spy).to.have.been.called;
expect(spy).to.have.been.calledWith([]);
});
it("performs multiple actions", function () {
@@ -87,7 +87,7 @@ describe("iD.History", function () {
history.perform(action);
history.on('change', spy);
history.undo();
expect(spy).to.have.been.called;
expect(spy).to.have.been.calledWith([]);
});
});
@@ -97,7 +97,7 @@ describe("iD.History", function () {
history.undo();
history.on('change', spy);
history.redo();
expect(spy).to.have.been.called;
expect(spy).to.have.been.calledWith([]);
});
});