From c8f162b8f03cd6bd050dabda2f0c6268ed8fcbc9 Mon Sep 17 00:00:00 2001 From: Milos Brzakovic Date: Tue, 13 Jul 2021 19:51:32 +0200 Subject: [PATCH] select - differentiate parent/child selection introduce more accessible shortcuts --- data/core.yaml | 1 + data/shortcuts.json | 8 +++++++- modules/modes/select.js | 39 +++++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 39e8de917..3e078a375 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -2300,6 +2300,7 @@ en: first: "Jump to first node" last: "Jump to last node" parent: "Select parent way" + child: "Select child node" change_parent: "Switch parent way" editing: title: "Editing" diff --git a/data/shortcuts.json b/data/shortcuts.json index e7fe736a4..cf1d94f8e 100644 --- a/data/shortcuts.json +++ b/data/shortcuts.json @@ -159,9 +159,15 @@ "text": "shortcuts.browsing.vertex_selected.last" }, { - "shortcuts": ["|"], + "modifiers": ["⌘"], + "shortcuts": ["↑"], "text": "shortcuts.browsing.vertex_selected.parent" }, + { + "modifiers": ["⌘"], + "shortcuts": ["↓"], + "text": "shortcuts.browsing.vertex_selected.child" + }, { "shortcuts": ["\\", "shortcuts.key.pause"], "text": "shortcuts.browsing.vertex_selected.change_parent" diff --git a/modules/modes/select.js b/modules/modes/select.js index cc122cfd5..7e6623540 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -244,7 +244,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) @@ -576,24 +577,30 @@ 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 parentIds = _focusedParentWayId ? [_focusedParentWayId] : parentWaysIdsOfSelection(false); + if (parentIds.length) return; + + var reselectIds = _focusedVertexIds && _focusedVertexIds.filter(id => context.hasEntity(id)); + if (!reselectIds || !reselectIds.length) return; + + if (currentSelectedIds.length === 1) _focusedParentWayId = currentSelectedIds[0]; + + context.enter( + mode.selectedIDs(_focusedVertexIds) + ); } };