Skip to content

Commit

Permalink
Fix address field overwriting existing data when switching features
Browse files Browse the repository at this point in the history
fixes #12060

This bug can occur occasionally under the following circumstances:

* map feature 1 is selected
* the cursor is in an address (sub) field
* map feature 2 gets selected directly
* now, in some cases, the contents of the address fields of feature 2 are written into feature 1's tags
  • Loading branch information
tyrasd committed Jun 5, 2024
1 parent b2fc4a4 commit 97d1aa5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
* Fix icons with inline css styles not properly being displayed on osm.org
* Properly sort map features with lifecycle prefixes in the _Past/Futures_ features ([#7582])
* Only consider features with either `landuse`, `natural`, `amentiy` or `leisure` tag to be classified as _Landuse_ areas
* Fix address field overwriting existing data when switching selected map features under certain circumstances ([#10260])
#### :earth_asia: Localization
#### :hourglass: Performance
#### :mortar_board: Walkthrough / Help
Expand All @@ -68,6 +69,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
[#10181]: https://github.com/openstreetmap/iD/pull/10181
[#10255]: https://github.com/openstreetmap/iD/pull/10255
[#10257]: https://github.com/openstreetmap/iD/pull/10257
[#10260]: https://github.com/openstreetmap/iD/issues/10260
[@zbycz]: https://github.com/zbycz


Expand Down
45 changes: 22 additions & 23 deletions modules/ui/fields/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { presetManager } from '../../presets';
import { fileFetcher } from '../../core/file_fetcher';
import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo';
import { uiCombobox } from '../combobox';
import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';
import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent, utilTriggerEvent } from '../../util';
import { t } from '../../core/localizer';


Expand Down Expand Up @@ -235,6 +235,7 @@ export function uiFieldAddress(field, context) {
if (d.isAutoStreetPlace) {
// set subtag depending on selected entry
d.id = selected ? selected.type : 'street';
utilTriggerEvent(d3_select(this), 'change');
}
})
);
Expand Down Expand Up @@ -283,35 +284,33 @@ export function uiFieldAddress(field, context) {

function change(onInput) {
return function() {
setTimeout(() => {
var tags = {};
var tags = {};

_wrap.selectAll('input')
.each(function (subfield) {
var key = field.key + ':' + subfield.id;
_wrap.selectAll('input')
.each(function (subfield) {
var key = field.key + ':' + subfield.id;

var value = this.value;
if (!onInput) value = context.cleanTagValue(value);
var value = this.value;
if (!onInput) value = context.cleanTagValue(value);

// don't override multiple values with blank string
if (Array.isArray(_tags[key]) && !value) return;
// don't override multiple values with blank string
if (Array.isArray(_tags[key]) && !value) return;

if (subfield.isAutoStreetPlace) {
if (subfield.id === 'street') {
tags[`${field.key}:place`] = undefined;
} else if (subfield.id === 'place') {
tags[`${field.key}:street`] = undefined;
}
if (subfield.isAutoStreetPlace) {
if (subfield.id === 'street') {
tags[`${field.key}:place`] = undefined;
} else if (subfield.id === 'place') {
tags[`${field.key}:street`] = undefined;
}
}

tags[key] = value || undefined;
});
tags[key] = value || undefined;
});

Object.keys(tags)
.filter(k => tags[k])
.forEach(k => _tags[k] = tags[k]);
dispatch.call('change', this, tags, onInput);
}, 0);
Object.keys(tags)
.filter(k => tags[k])
.forEach(k => _tags[k] = tags[k]);
dispatch.call('change', this, tags, onInput);
};
}

Expand Down

1 comment on commit 97d1aa5

@tyrasd
Copy link
Member Author

@tyrasd tyrasd commented on 97d1aa5 Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in the commit comment: the issue for this bug is actually #10260

Please sign in to comment.