mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
Include difference in history change events
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user