Make map pan to the location of the undone edit when undoing instead of the location of the edit before that (close #5831)

This commit is contained in:
Quincy Morgan
2019-03-27 18:02:21 -04:00
parent 53625a9364
commit 6fb8fcb86b
2 changed files with 27 additions and 18 deletions
+6 -4
View File
@@ -203,13 +203,14 @@ export function coreHistory(context) {
undo: function() {
d3_select(document).interrupt('history.perform');
var previous = _stack[_index].graph;
var previousStack = _stack[_index];
var previous = previousStack.graph;
while (_index > 0) {
_index--;
if (_stack[_index].annotation) break;
}
dispatch.call('undone', this, _stack[_index]);
dispatch.call('undone', this, _stack[_index], previousStack);
return change(previous, true);
},
@@ -218,13 +219,14 @@ export function coreHistory(context) {
redo: function() {
d3_select(document).interrupt('history.perform');
var previous = _stack[_index].graph;
var previousStack = _stack[_index];
var previous = previousStack.graph;
var tryIndex = _index;
while (tryIndex < _stack.length - 1) {
tryIndex++;
if (_stack[tryIndex].annotation) {
_index = tryIndex;
dispatch.call('redone', this, _stack[_index]);
dispatch.call('redone', this, _stack[_index], previousStack);
break;
}
}
+21 -14
View File
@@ -105,22 +105,29 @@ export function rendererMap(context) {
osm.on('change.map', immediateRedraw);
}
function didUndoOrRedo(stack, targetTransform) {
var mode = context.mode().id;
if (mode !== 'browse' && mode !== 'select') return;
var followSelected = false;
if (Array.isArray(stack.selectedIDs)) {
followSelected = (stack.selectedIDs.length === 1 && stack.selectedIDs[0][0] === 'n');
context.enter(
modeSelect(context, stack.selectedIDs).follow(followSelected)
);
}
if (!followSelected && targetTransform) {
map.transformEase(targetTransform);
}
}
context.history()
.on('change.map', immediateRedraw)
.on('undone.map redone.map', function(stack) {
var mode = context.mode().id;
if (mode !== 'browse' && mode !== 'select') return;
var followSelected = false;
if (Array.isArray(stack.selectedIDs)) {
followSelected = (stack.selectedIDs.length === 1 && stack.selectedIDs[0][0] === 'n');
context.enter(
modeSelect(context, stack.selectedIDs).follow(followSelected)
);
}
if (!followSelected && stack.transform) {
map.transformEase(stack.transform);
}
.on('undone.map', function(stack, fromStack) {
didUndoOrRedo(stack, fromStack.transform);
})
.on('redone.map', function(stack) {
didUndoOrRedo(stack, stack.transform);
});
context.background()