mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-07 03:41:33 +00:00
Hook into undos in a different way
This way doesn't depend on details of keybindings and the undo button. Also, implement this in DrawArea mode.
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user