From 2ebfcd174e9e8993ce24d7a073a735310b033f0b Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 3 May 2017 00:21:37 -0400 Subject: [PATCH] Don't redo into un-annotated edit states (closes #4006) --- modules/core/history.js | 16 ++++++++++------ test/spec/core/history.js | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/modules/core/history.js b/modules/core/history.js index a7118da76..67ce20290 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -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); }, diff --git a/test/spec/core/history.js b/test/spec/core/history.js index 13734de6e..2d6459f9b 100644 --- a/test/spec/core/history.js +++ b/test/spec/core/history.js @@ -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();