fix(mentions): fix to sort alphabetically and with start of words

This commit is contained in:
Jonathan Rainville 2021-07-09 15:43:10 -04:00 committed by Iuri Matias
parent 4277a6e7f4
commit 40fd390def
1 changed files with 35 additions and 3 deletions

View File

@ -123,12 +123,44 @@ Rectangle {
return true
}
const leftMatches = left[container.property.find(p => !!left[p])].toLowerCase().startsWith(formattedPlainTextFilter)
// Priorities:
// 1. Match at the start
// 2. Match in the start of one of the three words
// 3. Alphabetical order (also in case of multiple matches at the start of the name)
const rightMatches = right[container.property.find(p => !!right[p])].toLowerCase().startsWith(formattedPlainTextFilter)
const leftProp = left[container.property.find(p => !!left[p])].toLowerCase()
const rightProp = right[container.property.find(p => !!right[p])].toLowerCase()
// check the start of the string
const leftMatches = leftProp.startsWith(formattedPlainTextFilter)
const rightMatches = rightProp.startsWith(formattedPlainTextFilter)
if (leftMatches === true && rightMatches === true) {
return leftProp < rightProp
}
if (leftMatches || rightMatches) {
return leftMatches && !rightMatches
}
// Check for the start of the 3 word names
let leftMatchesIndex = leftProp.indexOf(" " + formattedPlainTextFilter)
let rightMatchesIndex = rightProp.indexOf(" " + formattedPlainTextFilter)
if (leftMatchesIndex === rightMatchesIndex) {
return leftProp < rightProp
}
// Change index so that -1 is not the smallest
if (leftMatchesIndex === -1) {
leftMatchesIndex = 999
}
if (rightMatchesIndex === -1) {
rightMatchesIndex = 999
}
return leftMatchesIndex < rightMatchesIndex
}
]
model: container.suggestionsModel