From 5433c8ff42427d25d5c256ecc82dd7581a3275e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 22 Dec 2020 11:51:22 -0800 Subject: [PATCH] Select all parent ways, not just common parents --- modules/modes/select.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/modes/select.js b/modules/modes/select.js index e9a84a912..2c6a0256c 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -23,7 +23,7 @@ import { osmNode, osmWay } from '../osm'; import * as Operations from '../operations/index'; import { uiCmd } from '../ui/cmd'; import { - utilArrayIntersection, utilDeepMemberSelector, utilEntityOrDeepMemberSelector, + utilArrayIntersection, utilArrayUnion, utilDeepMemberSelector, utilEntityOrDeepMemberSelector, utilEntitySelector, utilKeybinding, utilTotalExtent, utilGetAllNodes } from '../util'; @@ -85,6 +85,33 @@ export function modeSelect(context, selectedIDs) { } + // find the common parent ways for nextVertex, previousVertex + function allParents() { + var graph = context.graph(); + var allParents = []; + + for (var i = 0; i < selectedIDs.length; i++) { + var entity = context.hasEntity(selectedIDs[i]); + if (!entity || entity.geometry(graph) !== 'vertex') { + return []; // selection includes some not vertices + } + + var currParents = graph.parentWays(entity).map(function(w) { return w.id; }); + if (!allParents.length) { + allParents = currParents; + continue; + } + + allParents = utilArrayUnion(allParents, currParents); + if (!allParents.length) { + return []; + } + } + + return allParents; + } + + // find the common parent ways for nextVertex, previousVertex function commonParents() { var graph = context.graph(); @@ -565,7 +592,7 @@ export function modeSelect(context, selectedIDs) { function selectParent(d3_event) { d3_event.preventDefault(); - var parents = _relatedParent ? [_relatedParent] : commonParents(); + var parents = _relatedParent ? [_relatedParent] : allParents(); if (!parents) return; context.enter(