Skip to content

Commit 382edc1

Browse files
committed
[native] feat(search): Display folder path for folder search results
Signed-off-by: Marcel Klehr <[email protected]>
1 parent edff4da commit 382edc1

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/ui/components/native/Item.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
<v-list-item-subtitle v-if="item.type === 'bookmark'">
2323
{{ item.url | hostname }}
2424
</v-list-item-subtitle>
25-
<v-list-item-subtitle v-if="item.type === 'bookmark' && showFolderPath">
25+
<v-list-item-subtitle v-if="showFolderPath">
2626
<Breadcrumbs
2727
in-item
28-
:items="getBookmarkPath(item)"
28+
:items="item.type === 'bookmark' ? getBookmarkPath(item) : getFolderPath(item)"
2929
:tree="tree" />
3030
</v-list-item-subtitle>
3131
</v-list-item-content>
@@ -121,6 +121,14 @@ export default {
121121
},
122122
},
123123
methods: {
124+
getFolderPath(item) {
125+
const folders = [item]
126+
while (this.tree && folders[folders.length - 1 ] && String(folders[folders.length - 1 ].id) !== String(this.tree.id)) {
127+
folders.push(this.findItem(folders[folders.length - 1 ].parentId, this.tree))
128+
}
129+
folders.pop() // remove last folder
130+
return folders.reverse()
131+
},
124132
getBookmarkPath(item) {
125133
const folders = [item]
126134
while (this.tree && folders[folders.length - 1 ] && String(folders[folders.length - 1 ].id) !== String(this.tree.id)) {

src/ui/views/native/Tree.vue

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,11 @@ export default {
467467
}, 500)
468468
},
469469
search(query, tree) {
470-
return Object.values(tree.index.bookmark)
470+
return Object.values(tree.index.folder)
471471
.filter(item => {
472472
const matchTitleFully = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
473473
const matchTitlePartially = item.title ? query.split(' ').every(term => item.title.toLowerCase().includes(term)) : false
474-
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
475-
return matchUrl || matchTitleFully || matchTitlePartially
474+
return matchTitleFully || matchTitlePartially
476475
})
477476
.sort((a, b) => {
478477
const matchTitlePartiallyA = a.title ? query.split(' ').every(term => a.title.toLowerCase().includes(term)) : false
@@ -483,7 +482,25 @@ export default {
483482
const matchTitleA = a.title ? query.split(' ').every(term => a.title.toLowerCase().split(' ').some(word => word === term)) : false
484483
const matchTitleB = b.title ? query.split(' ').every(term => b.title.toLowerCase().split(' ').some(word => word === term)) : false
485484
return matchTitleA ? (matchTitleB ? 0 : -1) : 1
486-
})
485+
}).concat(
486+
Object.values(tree.index.bookmark)
487+
.filter(item => {
488+
const matchTitleFully = item.title ? query.split(' ').every(term => item.title.toLowerCase().split(' ').some(word => word === term)) : false
489+
const matchTitlePartially = item.title ? query.split(' ').every(term => item.title.toLowerCase().includes(term)) : false
490+
const matchUrl = query.split(' ').every(term => item.url.toLowerCase().includes(term))
491+
return matchUrl || matchTitleFully || matchTitlePartially
492+
})
493+
.sort((a, b) => {
494+
const matchTitlePartiallyA = a.title ? query.split(' ').every(term => a.title.toLowerCase().includes(term)) : false
495+
const matchTitlePartiallyB = b.title ? query.split(' ').every(term => b.title.toLowerCase().includes(term)) : false
496+
return matchTitlePartiallyA ? (matchTitlePartiallyB ? 0 : -1) : 1
497+
})
498+
.sort((a, b) => {
499+
const matchTitleA = a.title ? query.split(' ').every(term => a.title.toLowerCase().split(' ').some(word => word === term)) : false
500+
const matchTitleB = b.title ? query.split(' ').every(term => b.title.toLowerCase().split(' ').some(word => word === term)) : false
501+
return matchTitleA ? (matchTitleB ? 0 : -1) : 1
502+
})
503+
)
487504
},
488505
goBack() {
489506
if (this.isAddingBookmark) {

0 commit comments

Comments
 (0)