From 2fff6aec9363c935c18e02679caf19207a61fe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Mon, 21 Dec 2020 21:59:50 -0800 Subject: [PATCH 1/7] Added shortcut to select parent way --- data/core.yaml | 1 + data/shortcuts.json | 4 ++++ modules/modes/select.js | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/data/core.yaml b/data/core.yaml index cf60722c6..4f7e80dd5 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -2258,6 +2258,7 @@ en: next: "Jump to next node" first: "Jump to first node" last: "Jump to last node" + parent: "Select parent way" change_parent: "Switch parent way" editing: title: "Editing" diff --git a/data/shortcuts.json b/data/shortcuts.json index 2997ed427..dfad38e8c 100644 --- a/data/shortcuts.json +++ b/data/shortcuts.json @@ -158,6 +158,10 @@ "shortcuts": ["}", "⇟"], "text": "shortcuts.browsing.vertex_selected.last" }, + { + "shortcuts": [">"], + "text": "shortcuts.browsing.vertex_selected.parent" + }, { "shortcuts": ["\\", "shortcuts.key.pause"], "text": "shortcuts.browsing.vertex_selected.change_parent" diff --git a/modules/modes/select.js b/modules/modes/select.js index b0b98d183..01946f1c2 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -245,6 +245,7 @@ export function modeSelect(context, selectedIDs) { .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧' + key)), scaleSelection(1/1.05)) .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧⌥' + key)), scaleSelection(1/Math.pow(1.05, 5))) .on(['\\', 'pause'], nextParent) + .on('>', selectParent) .on('⎋', esc, true); d3_select(document) @@ -561,6 +562,15 @@ export function modeSelect(context, selectedIDs) { .classed('related', true); } } + + function selectParent(d3_event) { + d3_event.preventDefault(); + if (_relatedParent) { + context.enter( + modeSelect(context, [_relatedParent]) + ); + } + } }; From acc127bb7fcf2a54d071a8ea46592dd4c69e9075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Mon, 21 Dec 2020 23:38:26 -0800 Subject: [PATCH 2/7] Select all parent ways if specific parent way not selected --- modules/modes/select.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/modes/select.js b/modules/modes/select.js index 01946f1c2..c2bc8dfd8 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -565,11 +565,12 @@ export function modeSelect(context, selectedIDs) { function selectParent(d3_event) { d3_event.preventDefault(); - if (_relatedParent) { - context.enter( - modeSelect(context, [_relatedParent]) - ); - } + var parents = _relatedParent ? [_relatedParent] : commonParents(); + if (!parents) return; + + context.enter( + modeSelect(context, parents) + ); } }; From d95d204b62f1507d72c9fd9d5816210ad5240971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 22 Dec 2020 00:19:55 -0800 Subject: [PATCH 3/7] Recurse up, not down --- data/shortcuts.json | 2 +- modules/modes/select.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/shortcuts.json b/data/shortcuts.json index dfad38e8c..3453911ee 100644 --- a/data/shortcuts.json +++ b/data/shortcuts.json @@ -159,7 +159,7 @@ "text": "shortcuts.browsing.vertex_selected.last" }, { - "shortcuts": [">"], + "shortcuts": ["<"], "text": "shortcuts.browsing.vertex_selected.parent" }, { diff --git a/modules/modes/select.js b/modules/modes/select.js index c2bc8dfd8..288aef9b3 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -245,7 +245,7 @@ export function modeSelect(context, selectedIDs) { .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧' + key)), scaleSelection(1/1.05)) .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧⌥' + key)), scaleSelection(1/Math.pow(1.05, 5))) .on(['\\', 'pause'], nextParent) - .on('>', selectParent) + .on('<', selectParent) .on('⎋', esc, true); d3_select(document) From e031ee3aef9622169909c77fb62e1a833e38d75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 22 Dec 2020 11:28:46 -0800 Subject: [PATCH 4/7] Ctrl+UpArrow for selecting parent way --- data/shortcuts.json | 3 ++- modules/modes/select.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/data/shortcuts.json b/data/shortcuts.json index 3453911ee..3819602b1 100644 --- a/data/shortcuts.json +++ b/data/shortcuts.json @@ -159,7 +159,8 @@ "text": "shortcuts.browsing.vertex_selected.last" }, { - "shortcuts": ["<"], + "modifiers": ["⌘"], + "shortcuts": ["↑"], "text": "shortcuts.browsing.vertex_selected.parent" }, { diff --git a/modules/modes/select.js b/modules/modes/select.js index 288aef9b3..e9a84a912 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -245,7 +245,7 @@ export function modeSelect(context, selectedIDs) { .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧' + key)), scaleSelection(1/1.05)) .on(utilKeybinding.minusKeys.map((key) => uiCmd('⇧⌥' + key)), scaleSelection(1/Math.pow(1.05, 5))) .on(['\\', 'pause'], nextParent) - .on('<', selectParent) + .on(uiCmd('⌘↑'), selectParent) .on('⎋', esc, true); d3_select(document) 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 5/7] 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( From 8e2301d3b7b82fc604218e7180a358f4e9938c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 22 Dec 2020 12:15:24 -0800 Subject: [PATCH 6/7] Consolidated parent selection functions --- modules/modes/select.js | 49 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/modules/modes/select.js b/modules/modes/select.js index 2c6a0256c..eda0411f3 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -85,10 +85,10 @@ export function modeSelect(context, selectedIDs) { } - // find the common parent ways for nextVertex, previousVertex - function allParents() { + // find the parent ways for nextVertex, previousVertex, and selectParent + function multipleParents(onlyCommonParents) { var graph = context.graph(); - var allParents = []; + var parents = []; for (var i = 0; i < selectedIDs.length; i++) { var entity = context.hasEntity(selectedIDs[i]); @@ -97,50 +97,23 @@ export function modeSelect(context, selectedIDs) { } var currParents = graph.parentWays(entity).map(function(w) { return w.id; }); - if (!allParents.length) { - allParents = currParents; + if (!parents.length) { + parents = currParents; continue; } - allParents = utilArrayUnion(allParents, currParents); - if (!allParents.length) { + parents = (onlyCommonParents ? utilArrayIntersection : utilArrayUnion)(parents, currParents); + if (!parents.length) { return []; } } - return allParents; - } - - - // find the common parent ways for nextVertex, previousVertex - function commonParents() { - var graph = context.graph(); - var commonParents = []; - - 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 (!commonParents.length) { - commonParents = currParents; - continue; - } - - commonParents = utilArrayIntersection(commonParents, currParents); - if (!commonParents.length) { - return []; - } - } - - return commonParents; + return parents; } function singularParent() { - var parents = commonParents(); + var parents = multipleParents(true); if (!parents || parents.length === 0) { _relatedParent = null; return null; @@ -570,7 +543,7 @@ export function modeSelect(context, selectedIDs) { function nextParent(d3_event) { d3_event.preventDefault(); - var parents = commonParents(); + var parents = multipleParents(true); if (!parents || parents.length < 2) return; var index = parents.indexOf(_relatedParent); @@ -592,7 +565,7 @@ export function modeSelect(context, selectedIDs) { function selectParent(d3_event) { d3_event.preventDefault(); - var parents = _relatedParent ? [_relatedParent] : allParents(); + var parents = _relatedParent ? [_relatedParent] : multipleParents(false); if (!parents) return; context.enter( From 3802a4809f1d1f7d0aedbb967f0f76ec2fd292be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 22 Dec 2020 12:22:33 -0800 Subject: [PATCH 7/7] Maintain selection if there are no parents --- modules/modes/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/modes/select.js b/modules/modes/select.js index eda0411f3..f84f64331 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -566,7 +566,7 @@ export function modeSelect(context, selectedIDs) { function selectParent(d3_event) { d3_event.preventDefault(); var parents = _relatedParent ? [_relatedParent] : multipleParents(false); - if (!parents) return; + if (!parents || parents.length === 0) return; context.enter( modeSelect(context, parents)