Skip to content

Commit

Permalink
Merge pull request #8264 from openstreetmap/1ec5-select-way-2225
Browse files Browse the repository at this point in the history
Add shortcut to select parent way(s)
  • Loading branch information
quincylvania authored Jan 6, 2021
2 parents da00571 + 3802a48 commit 872d820
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@
"shortcuts": ["}", ""],
"text": "shortcuts.browsing.vertex_selected.last"
},
{
"modifiers": [""],
"shortcuts": [""],
"text": "shortcuts.browsing.vertex_selected.parent"
},
{
"shortcuts": ["\\", "shortcuts.key.pause"],
"text": "shortcuts.browsing.vertex_selected.change_parent"
Expand Down
33 changes: 22 additions & 11 deletions modules/modes/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -85,10 +85,10 @@ export function modeSelect(context, selectedIDs) {
}


// find the common parent ways for nextVertex, previousVertex
function commonParents() {
// find the parent ways for nextVertex, previousVertex, and selectParent
function multipleParents(onlyCommonParents) {
var graph = context.graph();
var commonParents = [];
var parents = [];

for (var i = 0; i < selectedIDs.length; i++) {
var entity = context.hasEntity(selectedIDs[i]);
Expand All @@ -97,23 +97,23 @@ export function modeSelect(context, selectedIDs) {
}

var currParents = graph.parentWays(entity).map(function(w) { return w.id; });
if (!commonParents.length) {
commonParents = currParents;
if (!parents.length) {
parents = currParents;
continue;
}

commonParents = utilArrayIntersection(commonParents, currParents);
if (!commonParents.length) {
parents = (onlyCommonParents ? utilArrayIntersection : utilArrayUnion)(parents, currParents);
if (!parents.length) {
return [];
}
}

return commonParents;
return parents;
}


function singularParent() {
var parents = commonParents();
var parents = multipleParents(true);
if (!parents || parents.length === 0) {
_relatedParent = null;
return null;
Expand Down Expand Up @@ -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(uiCmd('⌘↑'), selectParent)
.on('⎋', esc, true);

d3_select(document)
Expand Down Expand Up @@ -542,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);
Expand All @@ -561,6 +562,16 @@ export function modeSelect(context, selectedIDs) {
.classed('related', true);
}
}

function selectParent(d3_event) {
d3_event.preventDefault();
var parents = _relatedParent ? [_relatedParent] : multipleParents(false);
if (!parents || parents.length === 0) return;

context.enter(
modeSelect(context, parents)
);
}
};


Expand Down

0 comments on commit 872d820

Please sign in to comment.