Skip to content

Commit 64be806

Browse files
authored
add hotkey for traverse to parent node (#606)
* add support for select parent hotkey * remove outward attr on unselect
1 parent 158e40b commit 64be806

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

app/features/selectable.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function Selectable(visbug) {
5454
hotkeys(`${metaKey}+g,${metaKey}+shift+g`, on_group)
5555
hotkeys('tab,shift+tab,enter,shift+enter', on_keyboard_traversal)
5656
hotkeys(`${metaKey}+shift+enter`, on_select_children)
57+
hotkeys(`shift+'`, on_select_parent)
5758
}
5859

5960
const unlisten = () => {
@@ -106,6 +107,7 @@ export function Selectable(visbug) {
106107
'data-label-id': null,
107108
'data-pseudo-select': null,
108109
'data-measuring': null,
110+
'data-outward': null,
109111
}))
110112

111113
selected = selected.filter(node => node.getAttribute('data-label-id') !== id)
@@ -453,6 +455,7 @@ export function Selectable(visbug) {
453455
'data-selected-hide': null,
454456
'data-label-id': null,
455457
'data-pseudo-select': null,
458+
'data-outward': null,
456459
}))
457460

458461
$('[data-pseudo-select]').forEach(hover =>
@@ -715,6 +718,31 @@ export function Selectable(visbug) {
715718
}
716719
}
717720

721+
const on_select_parent = (e, {key}) => {
722+
const targets = selected.reduce((parents, node) => {
723+
const parent_element = node.parentElement;
724+
725+
if (parent_element.hasAttribute('data-outward'))
726+
return parents
727+
728+
parent_element.setAttribute('data-outward', true)
729+
parents.push(parent_element)
730+
731+
return parents
732+
}, [])
733+
734+
if (targets.length) {
735+
e.preventDefault()
736+
e.stopPropagation()
737+
738+
targets.forEach(node => {
739+
if (node && node !== document.body) {
740+
select(node)
741+
}
742+
})
743+
}
744+
}
745+
718746
watchImagesForUpload()
719747
listen()
720748

0 commit comments

Comments
 (0)