From a0de2c770600befb9914938ea286676c3b1ec84a Mon Sep 17 00:00:00 2001 From: Alex Hennings Date: Thu, 9 Jul 2020 11:05:51 -0400 Subject: [PATCH 1/3] Fix https://github.com/openstreetmap/iD/issues/7627 Accept a variety of formats in Feature Search when specifying an element by type and id. For example: n123, n 123, node123, node 123 or even https://www.openstreetmap.org/node/123/history#map=19/43.66140/-70.25415 --- modules/ui/feature_list.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index 1989e7a210..bef2c454ca 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -122,14 +122,16 @@ export function uiFeatureList(context) { if (!q) return result; - var idMatch = q.match(/^([nwr])([0-9]+)$/); + var idMatch = q.match(/^(.*[^\w])?(node|n|way|w|relation|r)[^\w]?([0-9]+)([^\w].*)?$/i); if (idMatch) { + var elemType = idMatch[2][0]; + var elemId = idMatch[3]; result.push({ - id: idMatch[0], - geometry: idMatch[1] === 'n' ? 'point' : idMatch[1] === 'w' ? 'line' : 'relation', - type: idMatch[1] === 'n' ? t('inspector.node') : idMatch[1] === 'w' ? t('inspector.way') : t('inspector.relation'), - name: idMatch[2] + id: elemType + elemId, + geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation', + type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : t('inspector.relation'), + name: elemId }); } From 009f7f2664649b9fb801e267b9842994bcb5642b Mon Sep 17 00:00:00 2001 From: Alex Hennings Date: Thu, 9 Jul 2020 11:08:15 -0400 Subject: [PATCH 2/3] Fixing whitespace. --- modules/ui/feature_list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index bef2c454ca..f6979e8158 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -125,8 +125,8 @@ export function uiFeatureList(context) { var idMatch = q.match(/^(.*[^\w])?(node|n|way|w|relation|r)[^\w]?([0-9]+)([^\w].*)?$/i); if (idMatch) { - var elemType = idMatch[2][0]; - var elemId = idMatch[3]; + var elemType = idMatch[2][0]; + var elemId = idMatch[3]; result.push({ id: elemType + elemId, geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation', From 0789b861b47fb59b3810efe258c2c256a234f2fa Mon Sep 17 00:00:00 2001 From: Alex Hennings Date: Fri, 10 Jul 2020 13:37:16 -0400 Subject: [PATCH 3/3] Updating regex to simplify and account for leading zeros in the element id. --- modules/ui/feature_list.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index f6979e8158..2309dd6e8f 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -122,11 +122,11 @@ export function uiFeatureList(context) { if (!q) return result; - var idMatch = q.match(/^(.*[^\w])?(node|n|way|w|relation|r)[^\w]?([0-9]+)([^\w].*)?$/i); + var idMatch = q.match(/(?:^|\W)(node|way|relation|[nwr])\W?0*([1-9]\d*)(?:\W|$)/i); if (idMatch) { - var elemType = idMatch[2][0]; - var elemId = idMatch[3]; + var elemType = idMatch[1].charAt(0); + var elemId = idMatch[2]; result.push({ id: elemType + elemId, geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation',