mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
@@ -173,12 +173,11 @@ export function coreHistory(context) {
|
||||
},
|
||||
|
||||
|
||||
// Back to the previous annotated state or index = 0.
|
||||
undo: function() {
|
||||
d3.select(document).interrupt('history.perform');
|
||||
|
||||
var previous = stack[index].graph;
|
||||
|
||||
// Pop to the next annotated state.
|
||||
while (index > 0) {
|
||||
index--;
|
||||
if (stack[index].annotation) break;
|
||||
@@ -189,16 +188,21 @@ export function coreHistory(context) {
|
||||
},
|
||||
|
||||
|
||||
// Forward to the next annotated state.
|
||||
redo: function() {
|
||||
d3.select(document).interrupt('history.perform');
|
||||
|
||||
var previous = stack[index].graph;
|
||||
while (index < stack.length - 1) {
|
||||
index++;
|
||||
if (stack[index].annotation) break;
|
||||
var tryIndex = index;
|
||||
while (tryIndex < stack.length - 1) {
|
||||
tryIndex++;
|
||||
if (stack[tryIndex].annotation) {
|
||||
index = tryIndex;
|
||||
dispatch.call('redone', this, stack[index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dispatch.call('redone', this, stack[index]);
|
||||
return change(previous);
|
||||
},
|
||||
|
||||
|
||||
@@ -214,14 +214,23 @@ describe('iD.History', function () {
|
||||
expect(history.redo().changes()).to.eql({});
|
||||
});
|
||||
|
||||
it('emits an redone event', function () {
|
||||
history.perform(action);
|
||||
it('does redo into an annotated state', function () {
|
||||
history.perform(action, 'annotation');
|
||||
history.on('redone', spy);
|
||||
history.undo();
|
||||
history.on('change', spy);
|
||||
history.redo();
|
||||
expect(history.undoAnnotation()).to.equal('annotation');
|
||||
expect(spy).to.have.been.called;
|
||||
});
|
||||
|
||||
it('does not redo into a non-annotated state', function () {
|
||||
history.perform(action);
|
||||
history.on('redone', spy);
|
||||
history.undo();
|
||||
history.redo();
|
||||
expect(spy).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('emits a change event', function () {
|
||||
history.perform(action);
|
||||
history.undo();
|
||||
|
||||
Reference in New Issue
Block a user