mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
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:
@@ -15,7 +15,7 @@ export function behaviorSelect(context) {
|
||||
var isShowAlways = +context.storage('edit-menu-show-always') === 1;
|
||||
var tolerance = 4;
|
||||
var _lastMouse = null;
|
||||
var _suppressMenu = true;
|
||||
var _showMenu = false;
|
||||
var _p1 = null;
|
||||
|
||||
// use pointer events on supported platforms; fallback to mouse events
|
||||
@@ -63,7 +63,7 @@ export function behaviorSelect(context) {
|
||||
d3_select(window)
|
||||
.on(_pointerPrefix + 'up.select', pointerup, true);
|
||||
|
||||
_suppressMenu = !isShowAlways;
|
||||
_showMenu = isShowAlways;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ export function behaviorSelect(context) {
|
||||
if (!_p1) {
|
||||
_p1 = point();
|
||||
}
|
||||
_suppressMenu = false;
|
||||
_showMenu = true;
|
||||
click();
|
||||
}
|
||||
|
||||
@@ -127,39 +127,47 @@ export function behaviorSelect(context) {
|
||||
datum = datum.parents[0];
|
||||
}
|
||||
|
||||
var newMode;
|
||||
|
||||
if (datum instanceof osmEntity) { // clicked an entity..
|
||||
var selectedIDs = context.selectedIDs();
|
||||
context.selectedNoteID(null);
|
||||
context.selectedErrorID(null);
|
||||
|
||||
if (!isMultiselect) {
|
||||
if (selectedIDs.length > 1 && (!_suppressMenu && !isShowAlways)) {
|
||||
if (selectedIDs.length > 1 && (_showMenu && !isShowAlways)) {
|
||||
// multiple things already selected, just show the menu...
|
||||
mode.suppressMenu(false).reselect();
|
||||
mode.reselect().showMenu();
|
||||
} else {
|
||||
if (mode.id !== 'select' || !utilArrayIdentical(mode.selectedIDs(), [datum.id])) {
|
||||
newMode = modeSelect(context, [datum.id]);
|
||||
// select a single thing if it's not already selected
|
||||
context.enter(modeSelect(context, [datum.id]).suppressMenu(_suppressMenu));
|
||||
context.enter(newMode);
|
||||
if (_showMenu) newMode.showMenu();
|
||||
} else {
|
||||
mode.suppressMenu(_suppressMenu).reselect();
|
||||
mode.reselect();
|
||||
if (_showMenu) mode.showMenu();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (selectedIDs.indexOf(datum.id) !== -1) {
|
||||
// clicked entity is already in the selectedIDs list..
|
||||
if (!_suppressMenu && !isShowAlways) {
|
||||
if (_showMenu && !isShowAlways) {
|
||||
// don't deselect clicked entity, just show the menu.
|
||||
mode.suppressMenu(false).reselect();
|
||||
mode.reselect().showMenu();
|
||||
} else {
|
||||
// deselect clicked entity, then reenter select mode or return to browse mode..
|
||||
selectedIDs = selectedIDs.filter(function(id) { return id !== datum.id; });
|
||||
context.enter(selectedIDs.length ? modeSelect(context, selectedIDs) : modeBrowse(context));
|
||||
}
|
||||
} else {
|
||||
|
||||
// clicked entity is not in the selected list, add it..
|
||||
selectedIDs = selectedIDs.concat([datum.id]);
|
||||
context.enter(modeSelect(context, selectedIDs).suppressMenu(_suppressMenu));
|
||||
newMode = modeSelect(context, selectedIDs);
|
||||
context.enter(newMode);
|
||||
if (_showMenu) newMode.showMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,13 +195,13 @@ export function behaviorSelect(context) {
|
||||
}
|
||||
|
||||
// reset for next time..
|
||||
_suppressMenu = true;
|
||||
_showMenu = false;
|
||||
}
|
||||
|
||||
|
||||
function behavior(selection) {
|
||||
_lastMouse = null;
|
||||
_suppressMenu = true;
|
||||
_showMenu = false;
|
||||
_p1 = null;
|
||||
|
||||
d3_select(window)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -30,8 +30,6 @@ export function uiEditMenu(context) {
|
||||
var editMenu = function(selection) {
|
||||
if (!_operations.length) return;
|
||||
|
||||
selection.node().focus();
|
||||
|
||||
var offset = [0, 0];
|
||||
var viewport = context.surfaceRect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user