diff --git a/js/id/graph/history.js b/js/id/graph/history.js index 3d027d042..142a9eeca 100644 --- a/js/id/graph/history.js +++ b/js/id/graph/history.js @@ -1,7 +1,7 @@ iD.History = function() { var stack, index, imagery_used = 'Bing', - dispatch = d3.dispatch('change'); + dispatch = d3.dispatch('change', 'undone', 'redone'); function perform(actions) { actions = Array.prototype.slice.call(actions); @@ -62,6 +62,7 @@ iD.History = function() { if (stack[index].annotation) break; } + dispatch.undone(); change(previous); }, @@ -73,6 +74,7 @@ iD.History = function() { if (stack[index].annotation) break; } + dispatch.redone(); change(previous); }, diff --git a/js/id/modes/draw_area.js b/js/id/modes/draw_area.js index 2fe02f37c..026aa5bbc 100644 --- a/js/id/modes/draw_area.js +++ b/js/id/modes/draw_area.js @@ -112,16 +112,22 @@ iD.modes.DrawArea = function(wayId) { d3.select(document) .call(keybinding); + + history.on('undone.drawline', function () { + controller.enter(iD.modes.Browse()); + }); }; mode.exit = function() { - var surface = mode.map.surface; + var map = mode.map, + surface = map.surface, + history = mode.history; surface.selectAll('.way, .node') .classed('active', false); - mode.map.tail(false); - mode.map.fastEnable(true); + map.tail(false); + map.fastEnable(true); surface .on('mousemove.drawarea', null) @@ -129,6 +135,8 @@ iD.modes.DrawArea = function(wayId) { keybinding.off(); + history.on('undone.drawline', null); + window.setTimeout(function() { mode.map.dblclickEnable(true); }, 1000); diff --git a/js/id/modes/draw_line.js b/js/id/modes/draw_line.js index e857bafe4..95719a6a9 100644 --- a/js/id/modes/draw_line.js +++ b/js/id/modes/draw_line.js @@ -126,11 +126,6 @@ iD.modes.DrawLine = function(wayId, direction) { controller.enter(iD.modes.Select(way, true)); } - function undo() { - history.undo(); - controller.enter(iD.modes.Browse()); - } - surface .on('mousemove.drawline', mousemove) .on('click.drawline', click); @@ -139,26 +134,27 @@ iD.modes.DrawLine = function(wayId, direction) { .on('⌫', backspace) .on('⌦', del) .on('⎋', ret) - .on('↩', ret) - .on('⌘-Z', undo) - .on('⌃-Z', undo); + .on('↩', ret); d3.select(document) .call(keybinding); - d3.select('#undo') - .on('click.drawline', undo); + history.on('undone.drawline', function () { + controller.enter(iD.modes.Browse()); + }); }; mode.exit = function() { - var surface = mode.map.surface; + var map = mode.map, + surface = map.surface, + history = mode.history; surface.selectAll('.way, .node') .classed('active', false); - mode.map.tail(false); - mode.map.fastEnable(true); - mode.map.minzoom(0); + map.tail(false); + map.fastEnable(true); + map.minzoom(0); surface .on('mousemove.drawline', null) @@ -166,7 +162,7 @@ iD.modes.DrawLine = function(wayId, direction) { keybinding.off(); - d3.select('#undo').on('click.drawline', null); + history.on('undone.drawline', null); window.setTimeout(function() { mode.map.dblclickEnable(true); diff --git a/test/spec/graph/history.js b/test/spec/graph/history.js index 554b22a82..309d396a1 100644 --- a/test/spec/graph/history.js +++ b/test/spec/graph/history.js @@ -83,6 +83,13 @@ describe("iD.History", function () { expect(history.redoAnnotation()).to.equal("annotation"); }); + it("emits an undone event", function () { + history.perform(action); + history.on('undone', spy); + history.undo(); + expect(spy).to.have.been.called; + }); + it("emits a change event", function () { history.perform(action); history.on('change', spy); @@ -92,6 +99,14 @@ describe("iD.History", function () { }); describe("#redo", function () { + it("emits an redone event", function () { + history.perform(action); + history.undo(); + history.on('change', spy); + history.redo(); + expect(spy).to.have.been.called; + }); + it("emits a change event", function () { history.perform(action); history.undo();