Skip to content

Commit e97d04e

Browse files
emanuelmutschlechnerAkryum
authored andcommitted
fix: tree navigation with arrow keys (#665)
1 parent 6628719 commit e97d04e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/devtools/views/components/ComponentTree.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ export default {
9191
let instanceToSelect
9292
9393
if (key === LEFT) {
94-
if (current.expanded) {
94+
if (current.expanded && current.$children.filter(isComponentInstance).length) {
9595
current.collapse()
9696
} else if (current.$parent && current.$parent.expanded) {
9797
instanceToSelect = current.$parent
9898
}
9999
} else if (key === RIGHT) {
100-
if (current.expanded && current.$children.length) {
100+
if (current.expanded && current.$children.filter(isComponentInstance).length) {
101101
instanceToSelect = findByIndex(all, currentIndex + 1)
102102
} else {
103103
current.expand()
@@ -163,11 +163,15 @@ export default {
163163
}
164164
}
165165
166-
function getAllInstances (list) {
167-
return Array.prototype.concat.apply([], list.map(instance => {
168-
return [instance, ...getAllInstances(instance.$children)]
169-
}))
170-
}
166+
const isComponentInstance = object => typeof object !== 'undefined' && typeof object.instance !== 'undefined'
167+
168+
const getAllInstances = list => list.reduce((instances, i) => {
169+
if (isComponentInstance(i)) {
170+
instances.push(i)
171+
}
172+
instances = instances.concat(getAllInstances(i.$children))
173+
return instances
174+
}, [])
171175
172176
function findCurrent (all, check) {
173177
for (let i = 0; i < all.length; i++) {

0 commit comments

Comments
 (0)