mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 15:56:56 +02:00
Add history.pauseChangeDispatch / history.resumeChangeDispatch
To avoid dispatching change events at improper times
This commit is contained in:
+20
-5
@@ -36,6 +36,7 @@ export function coreHistory(context) {
|
||||
var duration = 150;
|
||||
var _imageryUsed = [];
|
||||
var _checkpoints = {};
|
||||
var _pausedGraph;
|
||||
var _stack;
|
||||
var _index;
|
||||
var _tree;
|
||||
@@ -104,11 +105,13 @@ export function coreHistory(context) {
|
||||
// determine difference and dispatch a change event
|
||||
function change(previous, isAnnotated) {
|
||||
var difference = coreDifference(previous, history.graph());
|
||||
dispatch.call('change', this, difference);
|
||||
if (isAnnotated) {
|
||||
// actions like dragging a node can fire lots of changes,
|
||||
// so use 'annotatedChange' to listen for grouped undo/redo changes
|
||||
dispatch.call('annotatedChange', this, difference);
|
||||
if (!_pausedGraph) {
|
||||
dispatch.call('change', this, difference);
|
||||
if (isAnnotated) {
|
||||
// actions like dragging a node can fire lots of changes,
|
||||
// so use 'annotatedChange' to listen for grouped undo/redo changes
|
||||
dispatch.call('annotatedChange', this, difference);
|
||||
}
|
||||
}
|
||||
return difference;
|
||||
}
|
||||
@@ -244,6 +247,18 @@ export function coreHistory(context) {
|
||||
},
|
||||
|
||||
|
||||
pauseChangeDispatch: function() {
|
||||
_pausedGraph = _stack[_index].graph;
|
||||
},
|
||||
|
||||
|
||||
resumeChangeDispatch: function() {
|
||||
var previous = _pausedGraph;
|
||||
_pausedGraph = null;
|
||||
return change(previous, true);
|
||||
},
|
||||
|
||||
|
||||
undoAnnotation: function() {
|
||||
var i = _index;
|
||||
while (i >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user