Remove delay in opening the edit menu

Don't show the edit menu for multiple selected relations
Streamline edit menu code, replacing the confusing "suppressMenu" system
This commit is contained in:
Quincy Morgan
2020-03-26 12:48:30 -07:00
parent 2a1fbcc3b8
commit 4a67e8c5dc
3 changed files with 56 additions and 78 deletions
+36 -64
View File
@@ -48,10 +48,8 @@ export function modeSelect(context, selectedIDs) {
modeDragNote(context).behavior
];
var inspector; // unused?
var _editMenu = uiEditMenu(context);
var _timeout = null;
var _editMenu; // uiEditMenu
var _newFeature = false;
var _suppressMenu = true;
var _follow = false;
@@ -146,45 +144,50 @@ export function modeSelect(context, selectedIDs) {
function closeMenu() {
if (_editMenu) _editMenu.close();
// remove any existing menu no matter how it was added
context.map().supersurface
.select('.edit-menu').remove();
}
mode.showMenu = function() {
function positionMenu() {
if (!_editMenu) return;
var entity = singular();
if (entity && entity.geometry(context.graph()) === 'relation') {
_suppressMenu = true;
} else {
var point = context.map().mouse();
var viewport = geoExtent(context.projection.clipExtent()).polygon();
if (point && geoPointInPolygon(point, viewport)) {
_editMenu.anchorLoc(point);
} else {
_suppressMenu = true;
}
}
}
function showMenu() {
// remove any displayed menu
closeMenu();
if (_editMenu) {
// disable menu if in wide selection, for example
if (!context.map().editableDataEnabled()) return;
// disable menu if in wide selection, for example
if (!context.map().editableDataEnabled()) return;
context.map().supersurface.call(_editMenu);
// don't show the menu for relations alone
if (selectedIDs.every(function(id) {
return context.graph().geometry(id) === 'relation';
})) return;
var point = context.map().mouse();
var viewport = geoExtent(context.projection.clipExtent()).polygon();
// make sure a vaild position can be determined
if (!point || !geoPointInPolygon(point, viewport)) return;
var surfaceNode = context.surface().node();
if (surfaceNode.focus) { // FF doesn't support it
// focus the surface or else clicking off the menu may not trigger modeBrowse
surfaceNode.focus();
}
}
// don't load the menu until it's needed
if (!_editMenu) _editMenu = uiEditMenu(context);
_editMenu
.anchorLoc(point)
.operations(operations);
// render the menu
context.map().supersurface.call(_editMenu);
};
function toggleMenu() {
if (context.map().supersurface.select('.edit-menu').empty()) {
positionMenu();
showMenu();
mode.showMenu();
} else {
closeMenu();
}
@@ -203,16 +206,7 @@ export function modeSelect(context, selectedIDs) {
mode.reselect = function() {
if (!checkSelectedIDs()) return;
var surfaceNode = context.surface().node();
if (surfaceNode.focus) { // FF doesn't support it
surfaceNode.focus();
}
positionMenu();
if (!_suppressMenu) {
showMenu();
}
return mode;
};
@@ -223,13 +217,6 @@ export function modeSelect(context, selectedIDs) {
};
mode.suppressMenu = function(val) {
if (!arguments.length) return _suppressMenu;
_suppressMenu = val;
return mode;
};
mode.follow = function(val) {
if (!arguments.length) return _follow;
_follow = val;
@@ -262,10 +249,8 @@ export function modeSelect(context, selectedIDs) {
}
});
// remove the existing menu element, if any
// remove any displayed menu
closeMenu();
_editMenu.operations(operations);
}
@@ -331,13 +316,6 @@ export function modeSelect(context, selectedIDs) {
context.map().pan([0,0]); // full redraw, to adjust z-sorting #2914
}
_timeout = window.setTimeout(function() {
positionMenu();
if (!_suppressMenu) {
showMenu();
}
}, 270); /* after any centerEase completes */
function update() {
closeMenu();
@@ -376,11 +354,6 @@ export function modeSelect(context, selectedIDs) {
if (!checkSelectedIDs()) return;
var surface = context.surface();
var entity = singular();
if (entity && entity.geometry(context.graph()) === 'relation') {
_suppressMenu = true;
}
surface.selectAll('.selected-member')
.classed('selected-member', false);
@@ -530,7 +503,6 @@ export function modeSelect(context, selectedIDs) {
mode.exit = function() {
if (_timeout) window.clearTimeout(_timeout);
if (inspector) wrap.call(inspector.close);
operations.forEach(function(operation) {