Skip to content

Commit 01e6055

Browse files
fix: hotkey to select tags ( Alt + 1,2,3, ... )
This PR adds keybindings for 'Alt + 1' through 'Alt + 9' to the Raw Tag Editor (), allowing users to quickly focus the value input field of the corresponding tag row (1st to 9th) in the tag list.
1 parent 9d16588 commit 01e6055

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

modules/ui/sections/raw_tag_editor.js

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../../util
1313
import { uiTooltip } from '..';
1414
import { allowUpperCaseTagValues } from '../../osm/tags';
1515
import { fileFetcher } from '../../core';
16+
import { uiCmd } from '../cmd';
1617

1718

1819
export function uiSectionRawTagEditor(id, context) {
@@ -659,6 +660,30 @@ export function uiSectionRawTagEditor(id, context) {
659660
_readOnlyTags = val;
660661
return section;
661662
};
663+
664+
665+
// register Alt + 1-9 keybindings
666+
if (context) {
667+
document.addEventListener('keydown', function(d3_event) {
668+
// check if the Alt key is pressed and the key is 1-9
669+
if (d3_event.altKey && /^[1-9]$/.test(d3_event.key)) {
670+
d3_event.preventDefault();
671+
d3_event.stopPropagation();
672+
var targetIndex = parseInt(d3_event.key, 10);
673+
var targetInput = section.selection().select(`.tag-list li:nth-child(${targetIndex}) div.inner-wrap div.value-wrap input`);
674+
if (!targetInput.empty()) {
675+
// blur current focus and shift to new input
676+
if (document.activeElement) {
677+
document.activeElement.blur();
678+
}
679+
targetInput.node().focus();
680+
section.reRender();
681+
}
682+
}
683+
});
684+
} else {
685+
console.warn('Context not available');
686+
}
662687

663688

664689
return utilRebind(section, dispatch, 'on');

0 commit comments

Comments
 (0)