Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select [selectChild] - differentiate parent/child selection #8577

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,9 @@ en:
last: "Jump to last node"
parent: "Select parent way"
change_parent: "Switch parent way"
way_selected:
title: "With way selected"
child: "Select child node"
mbrzakovic marked this conversation as resolved.
Show resolved Hide resolved
editing:
title: "Editing"
drawing:
Expand Down
24 changes: 17 additions & 7 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@
{
"shortcuts": ["map_data.highlight_edits.key"],
"text": "shortcuts.browsing.display_options.highlight_edits"
}
]
},
{
"rows": [
},
{
"section": "help",
"text": "shortcuts.browsing.help.title"
Expand All @@ -101,7 +97,11 @@
{
"shortcuts": ["shortcuts.toggle.key", "?"],
"text": "shortcuts.browsing.help.keyboard"
},
}
]
},
{
"rows": [
{
"section": "selecting",
"text": "shortcuts.browsing.selecting.title"
Expand Down Expand Up @@ -159,12 +159,22 @@
"text": "shortcuts.browsing.vertex_selected.last"
},
{
"shortcuts": ["|"],
"modifiers": ["⌘"],
"shortcuts": ["↑"],
"text": "shortcuts.browsing.vertex_selected.parent"
},
{
"shortcuts": ["\\", "shortcuts.key.pause"],
"text": "shortcuts.browsing.vertex_selected.change_parent"
},
{
"section": "way_selected",
"text": "shortcuts.browsing.way_selected.title"
},
{
"modifiers": ["⌘"],
"shortcuts": ["↓"],
"text": "shortcuts.browsing.way_selected.child"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion dist/locales/en.min.json

Large diffs are not rendered by default.

62 changes: 46 additions & 16 deletions modules/modes/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,31 @@ export function modeSelect(context, selectedIDs) {
return parents;
}

// find the child nodes for selected ways
function childNodeIdsOfSelection(onlyCommon) {
var graph = context.graph();
var childs = [];

for (var i = 0; i < selectedIDs.length; i++) {
var entity = context.hasEntity(selectedIDs[i]);

if (!entity || !['area', 'line'].includes(entity.geometry(graph))){
mbrzakovic marked this conversation as resolved.
Show resolved Hide resolved
return []; // selection includes non-area/non-line
}
var currChilds = graph.childNodes(entity).map(function(node) { return node.id; });
if (!childs.length) {
childs = currChilds;
continue;
}

childs = (onlyCommon ? utilArrayIntersection : utilArrayUnion)(childs, currChilds);
if (!childs.length) {
return [];
}
}

return childs;
}

function checkFocusedParent() {
if (_focusedParentWayId) {
Expand Down Expand Up @@ -244,7 +269,8 @@ 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'], focusNextParent)
.on('|', selectParent)
.on(uiCmd('⌘↑'), selectParent)
.on(uiCmd('⌘↓'), selectChild)
.on('⎋', esc, true);

d3_select(document)
Expand Down Expand Up @@ -576,24 +602,28 @@ export function modeSelect(context, selectedIDs) {

var currentSelectedIds = mode.selectedIDs();
var parentIds = _focusedParentWayId ? [_focusedParentWayId] : parentWaysIdsOfSelection(false);
if (!parentIds.length) return;

if (!parentIds.length) {
var reselectIds = _focusedVertexIds && _focusedVertexIds.filter(id => context.hasEntity(id));
context.enter(
mode.selectedIDs(parentIds)
);
// set this after re-entering the selection since we normally want it cleared on exit
_focusedVertexIds = currentSelectedIds;
}

if (reselectIds && reselectIds.length) {
if (currentSelectedIds.length === 1) _focusedParentWayId = currentSelectedIds[0];
context.enter(
mode.selectedIDs(_focusedVertexIds)
);
}
} else {
function selectChild(d3_event) {
d3_event.preventDefault();

context.enter(
mode.selectedIDs(parentIds)
);
// set this after re-entering the selection since we normally want it cleared on exit
_focusedVertexIds = currentSelectedIds;
}
var currentSelectedIds = mode.selectedIDs();

var childIds = _focusedVertexIds ? _focusedVertexIds.filter(id => context.hasEntity(id)) : childNodeIdsOfSelection(true);
if (!childIds || !childIds.length) return;

if (currentSelectedIds.length === 1) _focusedParentWayId = currentSelectedIds[0];

context.enter(
mode.selectedIDs(childIds)
);
}
};

Expand Down