enable keybindings for unavailable operations -> show info message

this should make it easier to discover what a given keypress was supposed to do (e.g. which operation it triggered)

closes #9896
This commit is contained in:
Martin Raifer
2025-05-15 17:01:30 +02:00
parent c11b661ef3
commit e25af7c05e
6 changed files with 50 additions and 26 deletions
+21 -7
View File
@@ -1,3 +1,5 @@
import { t } from '../core';
/* Creates a keybinding behavior for an operation */
export function behaviorOperation(context) {
var _operation;
@@ -7,19 +9,26 @@ export function behaviorOperation(context) {
// prevent operations during low zoom selection
if (!context.map().withinEditableZoom()) return;
if (_operation.availableForKeypress && !_operation.availableForKeypress()) return;
// ignore (temporarily) disabled operation keyboard shortcuts,
// e.g. Ctrl+C while text is selected
if (_operation.availableForKeypress?.() === false) return;
d3_event.preventDefault();
var disabled = _operation.disabled();
if (disabled) {
if (!_operation.available()) {
context.ui().flash
.duration(4000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation disabled')
.label(t.append('operations._unavailable', {
operation: t(`operations.${_operation.id}.title`) || _operation.id
}))();
} else if (_operation.disabled()) {
context.ui().flash
.duration(4000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation disabled')
.label(_operation.tooltip())();
} else {
context.ui().flash
.duration(2000)
@@ -35,14 +44,19 @@ export function behaviorOperation(context) {
function behavior() {
if (_operation && _operation.available()) {
context.keybinding()
.on(_operation.keys, keypress);
behavior.on();
}
return behavior;
}
behavior.on = function() {
context.keybinding()
.on(_operation.keys, keypress);
};
behavior.off = function() {
context.keybinding()
.off(_operation.keys);