Site > File Tree > Add fuzzy search

This commit is contained in:
brunosimon
2017-08-15 23:56:51 +02:00
parent 555bff11ab
commit 923d3558f6
5 changed files with 65 additions and 2 deletions
@@ -15,6 +15,42 @@ export default
content: { type: Object }
},
computed:
{
visible()
{
// Get and clean search
const search = this.$store.state.files.search.replace(/\ /g, '').toLowerCase()
// If no search value, return true
if(search === '')
{
return true
}
// Set up fuzzy search
const text = this.content.data.path.full
let searchPosition = 0
// Go through each character in the text
for(let n = 0; n < text.length; n++)
{
// If match a character in the search, highlight it
if(searchPosition < search.length && text[n].toLowerCase() === search[searchPosition])
{
searchPosition += 1
}
}
if(searchPosition !== search.length)
{
return false
}
return true
}
},
methods:
{
onNameClick()
@@ -1,4 +1,4 @@
<div>
<div v-show="visible">
<a href="#" class="name" :style="{ paddingLeft:depth * 20 + 'px' }" @click.prevent="onNameClick">
<file-icon class="icon" :extension="content.data.extension"></file-icon>
<span class="text">