Don't redo into un-annotated edit states

(closes #4006)
This commit is contained in:
Bryan Housel
2017-05-03 00:21:37 -04:00
parent b7c0176498
commit 2ebfcd174e
2 changed files with 22 additions and 9 deletions

View File

@@ -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);
},

View File

@@ -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();