allow to change the key of a multi-valued tag

fixes #8836
This commit is contained in:
Martin Raifer
2021-12-03 15:19:07 +01:00
parent 250763882d
commit b4bc7f49bb
3 changed files with 17 additions and 10 deletions

View File

@@ -48,6 +48,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
#### :tada: New Features
#### :sparkles: Usability & Accessibility
* Add a preview to colour fields, showing a native colour picker dialog on click ([#8782], thanks [@k-yle])
* Tag keys of a multi-selection can now also be changed in the tags editor when the tag values differ in the selected features. ([#8836])
#### :scissors: Operations
* Split operation now indicates more clearly when multiple ways will be affected and gives a hint how to restrict the operation to a single line ([#8818])
#### :camera: Street-Level
@@ -83,6 +84,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
[#8817]: https://github.com/openstreetmap/iD/pull/8817
[#8818]: https://github.com/openstreetmap/iD/issues/8818
[#8828]: https://github.com/openstreetmap/iD/pull/8828
[#8836]: https://github.com/openstreetmap/iD/issues/8836
[@k-yle]: https://github.com/k-yle
# 2.20.2

View File

@@ -161,7 +161,10 @@ export function uiEntityEditor(context) {
for (var k in changed) {
if (!k) continue;
var v = changed[k];
if (v !== undefined || tags.hasOwnProperty(k)) {
if (typeof v === 'object') {
// a "key only" tag change
tags[k] = tags[v.oldKey];
} else if (v !== undefined || tags.hasOwnProperty(k)) {
tags[k] = v;
}
}

View File

@@ -254,7 +254,7 @@ export function uiSectionRawTagEditor(id, context) {
.attr('title', function(d) { return d.key; })
.call(utilGetSetValue, function(d) { return d.key; })
.attr('readonly', function(d) {
return (isReadOnly(d) || (typeof d.value !== 'string')) || null;
return isReadOnly(d) || null;
});
items.selectAll('input.value')
@@ -488,27 +488,29 @@ export function uiSectionRawTagEditor(id, context) {
}
var row = this.parentNode.parentNode;
var inputVal = d3_select(row).selectAll('input.value');
var vNew = context.cleanTagValue(utilGetSetValue(inputVal));
_pendingChange = _pendingChange || {};
if (kOld) {
if (kOld === kNew) return;
// a tag key was renamed
_pendingChange[kNew] = _pendingChange[kOld] || { oldKey: kOld };
_pendingChange[kOld] = undefined;
} else {
// a new tag was added
let row = this.parentNode.parentNode;
let inputVal = d3_select(row).selectAll('input.value');
let vNew = context.cleanTagValue(utilGetSetValue(inputVal));
_pendingChange[kNew] = vNew;
utilGetSetValue(inputVal, vNew);
}
_pendingChange[kNew] = vNew;
// update the ordered key index so this row doesn't change position
var existingKeyIndex = _orderedKeys.indexOf(kOld);
if (existingKeyIndex !== -1) _orderedKeys[existingKeyIndex] = kNew;
d.key = kNew; // update datum to avoid exit/enter on tag update
d.value = vNew;
this.value = kNew;
utilGetSetValue(inputVal, vNew);
scheduleChange();
}