diff --git a/modules/behavior/operation.js b/modules/behavior/operation.js index cfaf60a22..f4249b254 100644 --- a/modules/behavior/operation.js +++ b/modules/behavior/operation.js @@ -9,7 +9,10 @@ export function behaviorOperation(context) { // prevent operations during low zoom selection if (!context.map().withinEditableZoom()) return; + if (_operation.availableForKeypress && !_operation.availableForKeypress()) return; + d3_event.preventDefault(); + var disabled = _operation.disabled(); if (disabled) { diff --git a/modules/operations/copy.js b/modules/operations/copy.js index d3bfa1c76..9ef7adbe6 100644 --- a/modules/operations/copy.js +++ b/modules/operations/copy.js @@ -1,5 +1,3 @@ -import { event as d3_event } from 'd3-selection'; - import { t } from '../core/localizer'; import { behaviorOperation } from '../behavior/operation'; import { uiCmd } from '../ui/cmd'; @@ -19,10 +17,6 @@ export function operationCopy(context, selectedIDs) { var operation = function() { - if (!getSelectionText()) { - d3_event.preventDefault(); - } - var graph = context.graph(); var selected = groupEntities(getFilteredIdsToCopy(), graph); var canCopy = []; @@ -97,11 +91,6 @@ export function operationCopy(context, selectedIDs) { } - function getSelectionText() { - return window.getSelection().toString(); - } - - operation.available = function() { return getFilteredIdsToCopy().length > 0; }; @@ -116,6 +105,13 @@ export function operationCopy(context, selectedIDs) { }; + operation.availableForKeypress = function() { + var selection = window.getSelection && window.getSelection(); + // if the user has text selected then let them copy that, not the selected feature + return !selection || !selection.toString(); + }; + + operation.tooltip = function() { var disable = operation.disabled(); return disable ?