From a2d3cf8f9a4d1c60fd44c5945e07334a5ebf84a9 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 3 Aug 2023 16:48:10 +0200 Subject: [PATCH] fix jumping cursor while editing in some input fields fixes #9233 --- CHANGELOG.md | 4 ++-- modules/ui/fields/address.js | 3 +++ modules/util/get_set_value.js | 14 +++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d72c3aa8..a2bd3a443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,12 +51,14 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix bug where "outlink" buttons would not be disabled on invalid values of `identifier` fields * Fix zooming/panning in KartaView photo layer after resizing the panel ([#8997]) * Fix clearing of contents of some input field when the respective tag is removed (e.g. when using the trash can icon on the UI field) +* Don't move the cursor to the end of (some) input fields while editing in the middle ([#9233]) #### :earth_asia: Localization #### :hourglass: Performance #### :mortar_board: Walkthrough / Help #### :hammer: Development [#8997]: https://github.com/openstreetmap/iD/issues/8997 +[#9233]: https://github.com/openstreetmap/iD/issues/9233 [#9786]: https://github.com/openstreetmap/iD/issues/9786 [#9664]: https://github.com/openstreetmap/iD/pull/9664 [@channel-s]: https://github.com/channel-s @@ -100,7 +102,6 @@ _Breaking developer changes, which may affect downstream projects or sites that * Properly handle case sensitive tag values in taginfo suggestions in raw tag editor ([#9640]) * Fix broken autocomplete of wikidata fields for some languages with country-codes ([#9638]) * Prevent certain tag values from corrupting css classes when they contain whitespaces ([#9637], thanks [@k-yle]) -* Don't move the cursor to the end of (some) input fields while editing in the middle ([#9233]) * Fix crash when using certain locales (e.g. `fr-FR`) ([#9737], thanks [@k-yle]) #### :earth_asia: Localization * Send `Accept-Language` header on Nominatim API calls ([#9501], thanks [@k-yle]) @@ -127,7 +128,6 @@ _Breaking developer changes, which may affect downstream projects or sites that [#8769]: https://github.com/openstreetmap/iD/pull/8769 [#8775]: https://github.com/openstreetmap/iD/pull/8775 [#7427]: https://github.com/openstreetmap/iD/issues/7427 -[#9233]: https://github.com/openstreetmap/iD/issues/9233 [#9433]: https://github.com/openstreetmap/iD/pull/9433 [#9482]: https://github.com/openstreetmap/iD/pull/9482 [#9483]: https://github.com/openstreetmap/iD/pull/9483 diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 19ff87d75..bbde62162 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -307,6 +307,9 @@ export function uiFieldAddress(field, context) { tags[key] = value || undefined; }); + Object.keys(tags) + .filter(k => tags[k]) + .forEach(k => _tags[k] = tags[k]); dispatch.call('change', this, tags, onInput); }, 0); }; diff --git a/modules/util/get_set_value.js b/modules/util/get_set_value.js index 1da96a135..d96e7c4cf 100644 --- a/modules/util/get_set_value.js +++ b/modules/util/get_set_value.js @@ -28,6 +28,13 @@ export function utilGetSetValue(selection, value, shouldUpdate) { } function stickyCursor(func) { + // only certain input element types allow manipulating the cursor + // see https://html.spec.whatwg.org/multipage/input.html#concept-input-apply + const supportedTypes = ['text', 'search', 'url', 'tel', 'password']; + if (!supportedTypes.includes(selection.node()?.type)) { + return func; + } + return function() { const cursor = { start: this.selectionStart, end: this.selectionEnd }; func.apply(this, arguments); @@ -43,12 +50,5 @@ export function utilGetSetValue(selection, value, shouldUpdate) { shouldUpdate = (a, b) => a !== b; } - // only certain input element types allow manipulating the cursor - // see https://html.spec.whatwg.org/multipage/input.html#concept-input-apply - const supportedTypes = ['text', 'search', 'url', 'tel', 'password']; - if (!supportedTypes.includes(this.type)) { - return selection.each(setValue(value, shouldUpdate)); - } - return selection.each(stickyCursor(setValue(value, shouldUpdate))); }