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

Add shortcut to select parent way(s) #8264

Merged
merged 7 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
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
4 changes: 4 additions & 0 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
"shortcuts": ["}", "⇟"],
"text": "shortcuts.browsing.vertex_selected.last"
},
{
"shortcuts": ["<"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Repeating this comment in a thread so it’s easier to discuss.)

I couldn’t think of an intuitive keyboard shortcut that was as convenient as the [ and ] shortcuts that it would complement. So I went with <, based on (of all things) the < operator in OverpassQL, which recurses up to the parent of a node or way. I’m open to other ideas.

< is a common character on keyboard layouts due to its prevalence in basic math. Just to be on the safe side, I consulted Apple’s visual guide to physical keyboard localizations and checked each of the 169 keyboard layouts available on macOS:

  • Hindi Devanagari, Khmer, Myanmar, Sinhala, and Tibetan Wylie lack a < key, though I didn’t check whether there are any dead keys that provide access to this character.
  • Chinese Pinyin, Chinese Shuangpin, and Thai lack a < key, but Thai keyboards have a <-labeled key, so I suspect the expectation is that users would switch to a QWERTY keyboard when necessary.

To accommodate these keyboard layouts, we could make the keyboard shortcut localizable, relying on an assumption that keyboard layouts generally correspond to languages. If we choose a letter as the keyboard shortcut instead, then it would definitely have to be localizable.

All the other keyboard layouts have a < key, but some require pressing both Shift and AltGr at the same time, which can be inconvenient.

Copy link
Collaborator Author

@1ec5 1ec5 Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally went with punctuation because it seems like iD generally reserves letters for editing operations and uses control keys or punctuation for navigation, which makes sense. The problem is that there are very few control keys left that aren’t used by iD or the browser, and very few punctuation characters are universal among keyboard layouts.

An alternative I didn’t consider earlier was Ctrl on Windows or ⌘↑ on macOS. These keys are physical keys on every keyboard, regardless of locale.

This combination is unlikely to cause a conflict with browsers. On Windows, Ctrl would move the caret to the beginning of the paragraph, but this shortcut would take effect when no text field has focus. On macOS, ⌘↑ would move the caret to the beginning of a text field or scroll to the top of the page, but iD doesn’t scroll like a page (cue request to jump to the North Pole). It’s also Finder’s shortcut for moving up to the containing folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but iD doesn’t scroll like a page

If the focus is somehow on the sidebar (but not one of its fields), then pressing ⌘↓ jumps to the bottom of the scroll view but ⌘↑ would select the parent ways instead of jumping to the top of the scroll view. I think this situation would be relatively rare, but hopefully there’s a way to special-case the shortcut to only occur when the canvas has focus. Otherwise, that would be a good argument for making the shortcut CtrlShift on Windows and ⇧⌘↑ on macOS.

"text": "shortcuts.browsing.vertex_selected.parent"
},
{
"shortcuts": ["\\", "shortcuts.key.pause"],
"text": "shortcuts.browsing.vertex_selected.change_parent"
Expand Down
11 changes: 11 additions & 0 deletions modules/modes/select.js
Original file line number Diff line number Diff line change
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('<', selectParent)
.on('⎋', esc, true);

d3_select(document)
Expand Down Expand Up @@ -561,6 +562,16 @@ export function modeSelect(context, selectedIDs) {
.classed('related', true);
}
}

function selectParent(d3_event) {
d3_event.preventDefault();
var parents = _relatedParent ? [_relatedParent] : commonParents();
if (!parents) return;

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


Expand Down