Site > Fuzzy Search > Add path highlights

This commit is contained in:
brunosimon
2017-08-29 00:38:28 +02:00
parent 923d3558f6
commit e0d2d449d1
4 changed files with 91 additions and 30 deletions
+29 -20
View File
@@ -15,39 +15,48 @@ export default
content: { type: Object }
},
data()
{
return {
matchingPositions: []
}
},
computed:
{
visible()
{
let visible = true
// Get and clean search
const search = this.$store.state.files.search.replace(/\ /g, '').toLowerCase()
const search = this.$store.state.files.search.replace(/ /g, '').toLowerCase()
// If no search value, return true
if(search === '')
if(search !== '')
{
return true
}
// Set up fuzzy search
const text = this.content.data.path.full.replace(/^\.\//, '')
let searchPosition = 0
this.matchingPositions = []
// 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])
// Go through each character in the text
for(let n = 0; n < text.length; n++)
{
searchPosition += 1
// If match a character in the search, highlight it
if(searchPosition < search.length && text[n].toLowerCase() === search[searchPosition])
{
searchPosition += 1
this.matchingPositions.push(n - this.content.data.path.directory.length + 1)
}
}
if(searchPosition !== search.length)
{
visible = false
}
}
if(searchPosition !== search.length)
{
return false
}
return true
return visible
}
},