mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Remove cacheing of disabled state for certain operations to avoid stale state (close #6296)
This commit is contained in:
@@ -16,7 +16,6 @@ export function operationCircularize(selectedIDs, context) {
|
||||
};
|
||||
var nodes = utilGetAllNodes(selectedIDs, context.graph());
|
||||
var coords = nodes.map(function(n) { return n.loc; });
|
||||
var _disabled;
|
||||
|
||||
var operation = function() {
|
||||
context.perform(action, operation.annotation());
|
||||
@@ -30,21 +29,21 @@ export function operationCircularize(selectedIDs, context) {
|
||||
};
|
||||
|
||||
|
||||
// don't cache this because the visible extent could change
|
||||
operation.disabled = function() {
|
||||
if (_disabled !== undefined) return _disabled;
|
||||
|
||||
_disabled = action.disabled(context.graph());
|
||||
if (_disabled) {
|
||||
return _disabled;
|
||||
var actionDisabled = action.disabled(context.graph());
|
||||
if (actionDisabled) {
|
||||
return actionDisabled;
|
||||
} else if (extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return _disabled = 'too_large';
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
return _disabled = 'not_downloaded';
|
||||
return 'not_downloaded';
|
||||
} else if (selectedIDs.some(context.hasHiddenConnections)) {
|
||||
return _disabled = 'connected_to_hidden';
|
||||
return 'connected_to_hidden';
|
||||
}
|
||||
|
||||
return _disabled = false;
|
||||
return false;
|
||||
|
||||
|
||||
function someMissing() {
|
||||
|
||||
@@ -12,7 +12,6 @@ export function operationMove(selectedIDs, context) {
|
||||
var extent = nodes.reduce(function(extent, node) {
|
||||
return extent.extend(node.extent(context.graph()));
|
||||
}, geoExtent());
|
||||
var _disabled;
|
||||
|
||||
|
||||
var operation = function() {
|
||||
@@ -27,19 +26,18 @@ export function operationMove(selectedIDs, context) {
|
||||
|
||||
|
||||
operation.disabled = function() {
|
||||
if (_disabled !== undefined) return _disabled;
|
||||
|
||||
if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return _disabled = 'too_large';
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
return _disabled = 'not_downloaded';
|
||||
return 'not_downloaded';
|
||||
} else if (selectedIDs.some(context.hasHiddenConnections)) {
|
||||
return _disabled = 'connected_to_hidden';
|
||||
return 'connected_to_hidden';
|
||||
} else if (selectedIDs.some(incompleteRelation)) {
|
||||
return _disabled = 'incomplete_relation';
|
||||
return 'incomplete_relation';
|
||||
}
|
||||
|
||||
return _disabled = false;
|
||||
return false;
|
||||
|
||||
|
||||
function someMissing() {
|
||||
|
||||
@@ -8,7 +8,6 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
var _entityID;
|
||||
var _entity;
|
||||
var _geometry;
|
||||
var _disabled;
|
||||
var action = chooseAction();
|
||||
if (action) {
|
||||
action.onCompletion = function() {
|
||||
@@ -59,24 +58,23 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
};
|
||||
|
||||
|
||||
// don't cache this because the visible extent could change
|
||||
operation.disabled = function() {
|
||||
if (!action) return '';
|
||||
if (_disabled !== undefined) return _disabled;
|
||||
|
||||
var extent = _entity.extent(context.graph());
|
||||
_disabled = action.disabled(context.graph());
|
||||
|
||||
if (_disabled) {
|
||||
return _disabled;
|
||||
} else if (_geometry !== 'vertex' && extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return _disabled = 'too_large';
|
||||
var actionDisabled = action.disabled(context.graph());
|
||||
if (actionDisabled) {
|
||||
return actionDisabled;
|
||||
} else if (_geometry !== 'vertex' &&
|
||||
_entity.extent(context.graph()).percentContainedIn(context.extent()) < 0.8) {
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
return _disabled = 'not_downloaded';
|
||||
return 'not_downloaded';
|
||||
} else if (selectedIDs.some(context.hasHiddenConnections)) {
|
||||
return _disabled = 'connected_to_hidden';
|
||||
return 'connected_to_hidden';
|
||||
}
|
||||
|
||||
return _disabled = false;
|
||||
return false;
|
||||
|
||||
|
||||
function someMissing() {
|
||||
|
||||
@@ -23,7 +23,6 @@ export function operationReflect(selectedIDs, context, axis) {
|
||||
var extent = nodes.reduce(function(extent, node) {
|
||||
return extent.extend(node.extent(context.graph()));
|
||||
}, geoExtent());
|
||||
var _disabled;
|
||||
|
||||
|
||||
var operation = function() {
|
||||
@@ -38,20 +37,20 @@ export function operationReflect(selectedIDs, context, axis) {
|
||||
};
|
||||
|
||||
|
||||
// don't cache this because the visible extent could change
|
||||
operation.disabled = function() {
|
||||
if (_disabled !== undefined) return _disabled;
|
||||
|
||||
if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return _disabled = 'too_large';
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
return _disabled = 'not_downloaded';
|
||||
return 'not_downloaded';
|
||||
} else if (selectedIDs.some(context.hasHiddenConnections)) {
|
||||
return _disabled = 'connected_to_hidden';
|
||||
return 'connected_to_hidden';
|
||||
} else if (selectedIDs.some(incompleteRelation)) {
|
||||
return _disabled = 'incomplete_relation';
|
||||
return 'incomplete_relation';
|
||||
}
|
||||
|
||||
return _disabled = false;
|
||||
return false;
|
||||
|
||||
|
||||
function someMissing() {
|
||||
|
||||
@@ -12,7 +12,6 @@ export function operationRotate(selectedIDs, context) {
|
||||
var extent = nodes.reduce(function(extent, node) {
|
||||
return extent.extend(node.extent(context.graph()));
|
||||
}, geoExtent());
|
||||
var _disabled;
|
||||
|
||||
|
||||
var operation = function() {
|
||||
@@ -26,19 +25,18 @@ export function operationRotate(selectedIDs, context) {
|
||||
|
||||
|
||||
operation.disabled = function() {
|
||||
if (_disabled !== undefined) return _disabled;
|
||||
|
||||
if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return _disabled = 'too_large';
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
return _disabled = 'not_downloaded';
|
||||
return 'not_downloaded';
|
||||
} else if (selectedIDs.some(context.hasHiddenConnections)) {
|
||||
return _disabled = 'connected_to_hidden';
|
||||
return 'connected_to_hidden';
|
||||
} else if (selectedIDs.some(incompleteRelation)) {
|
||||
return _disabled = 'incomplete_relation';
|
||||
return 'incomplete_relation';
|
||||
}
|
||||
|
||||
return _disabled = false;
|
||||
return false;
|
||||
|
||||
|
||||
function someMissing() {
|
||||
|
||||
Reference in New Issue
Block a user