mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-17 09:08:49 +00:00
fix(mentions): fix to sort alphabetically and with start of words
This commit is contained in:
parent
4277a6e7f4
commit
40fd390def
@ -123,12 +123,44 @@ Rectangle {
|
|||||||
return true
|
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
|
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
|
model: container.suggestionsModel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user