mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-12 16:52:10 -04:00
launcher v2: improve search result responsiveness, highlight matches
This commit is contained in:
@@ -35,6 +35,21 @@ Rectangle {
|
||||
|
||||
readonly property int computedIconSize: Math.min(48, Math.max(32, width * 0.45))
|
||||
|
||||
function highlightText(text, query, baseColor) {
|
||||
if (!text || !query || query.length === 0)
|
||||
return text;
|
||||
var lowerText = text.toLowerCase();
|
||||
var lowerQuery = query.toLowerCase();
|
||||
var idx = lowerText.indexOf(lowerQuery);
|
||||
if (idx === -1)
|
||||
return text;
|
||||
var before = text.substring(0, idx);
|
||||
var match = text.substring(idx, idx + query.length);
|
||||
var after = text.substring(idx + query.length);
|
||||
var highlightColor = Theme.primary;
|
||||
return '<span style="color:' + baseColor + '">' + before + '</span>' + '<span style="color:' + highlightColor + '; font-weight:600">' + match + '</span>' + '<span style="color:' + baseColor + '">' + after + '</span>';
|
||||
}
|
||||
|
||||
radius: Theme.cornerRadius
|
||||
color: isSelected ? Theme.primaryPressed : isHovered ? Theme.primaryHoverLight : "transparent"
|
||||
|
||||
@@ -55,11 +70,20 @@ Rectangle {
|
||||
materialIconSizeAdjustment: root.computedIconSize * 0.3
|
||||
}
|
||||
|
||||
StyledText {
|
||||
Text {
|
||||
width: parent.width
|
||||
text: root.item?.name ?? ""
|
||||
text: {
|
||||
var query = root.controller?.searchQuery ?? "";
|
||||
var name = root.item?.name ?? "";
|
||||
var baseColor = root.isSelected ? Theme.primary : Theme.surfaceText;
|
||||
if (!query)
|
||||
return name;
|
||||
return root.highlightText(name, query, baseColor);
|
||||
}
|
||||
textFormat: root.controller?.searchQuery ? Text.RichText : Text.PlainText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.weight: Font.Medium
|
||||
font.family: Theme.fontFamily
|
||||
color: root.isSelected ? Theme.primary : Theme.surfaceText
|
||||
elide: Text.ElideRight
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
|
||||
Reference in New Issue
Block a user