Add glassMxrph shell sources
Initial commit of the Quickshell desktop suite: bar, dock, launcher, settings, Control Center, dashboard, OSD, lock screen, desktop widgets, plugin host with the vendored Noctalia/Omarchy compatibility layer, helpers, packaging, tests and phase documentation. Includes the optimization work so far: usage widgets and dashboard gauges no longer animate continuously, desktop widgets pause while covered, system controls stop flickering on background polls, dock app matching uses an indexed catalog, and workspace ghosts are created only for occupied slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
99e64a7713
433 files changed
+57792
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import QtQuick
|
||||
import "../services"
|
||||
import "SearchLogic.js" as Search
|
||||
|
||||
QtObject {
|
||||
property string query: ""
|
||||
property int limit: 50
|
||||
property bool enabled: false
|
||||
readonly property var indexed: Search.index(ApplicationsService.launchable.map(entry => ({
|
||||
id: entry.id,
|
||||
title: entry.name,
|
||||
description: entry.genericName || entry.comment || entry.id,
|
||||
entry: entry,
|
||||
fields: [
|
||||
{
|
||||
text: entry.name
|
||||
},
|
||||
{
|
||||
text: entry.genericName,
|
||||
penalty: 150
|
||||
},
|
||||
{
|
||||
text: entry.id,
|
||||
penalty: 300
|
||||
},
|
||||
{
|
||||
text: entry.keywords.join(" "),
|
||||
penalty: 200
|
||||
},
|
||||
{
|
||||
text: entry.comment,
|
||||
penalty: 500
|
||||
}
|
||||
]
|
||||
})))
|
||||
readonly property var results: enabled ? Search.rank(indexed, query, limit) : []
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import "../core"
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
property var extensions: []
|
||||
readonly property var commands: SettingsRegistry.pages.map(page => ({
|
||||
id: page.command,
|
||||
title: page.title,
|
||||
description: page.description,
|
||||
page: page.id,
|
||||
available: page.available
|
||||
})).concat(extensions)
|
||||
// Extensions are registered by trusted QML code, never interpreted from search text.
|
||||
function registerCommand(command) {
|
||||
if (!command || !/^[a-z][a-z0-9-]*$/.test(command.id) || !command.title || typeof command.run !== "function" || commands.some(c => c.id === command.id))
|
||||
return false;
|
||||
extensions = extensions.concat([command]);
|
||||
return true;
|
||||
}
|
||||
function unregisterCommand(id) {
|
||||
extensions = extensions.filter(c => c.id !== id);
|
||||
}
|
||||
function execute(id) {
|
||||
const command = commands.find(c => c.id === id);
|
||||
if (!command)
|
||||
return false;
|
||||
if (command.run)
|
||||
command.run();
|
||||
else
|
||||
ShellState.openSettings(command.page);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import QtQuick
|
||||
import "SearchLogic.js" as Search
|
||||
|
||||
QtObject {
|
||||
property string query: ""
|
||||
property int limit: 50
|
||||
property bool enabled: false
|
||||
readonly property var indexed: Search.index(CommandRegistry.commands.map(command => ({
|
||||
id: command.id,
|
||||
title: command.title,
|
||||
description: command.description || "Shell command",
|
||||
command: true,
|
||||
fields: [
|
||||
{
|
||||
text: command.id
|
||||
},
|
||||
{
|
||||
text: command.title
|
||||
},
|
||||
{
|
||||
text: command.description,
|
||||
penalty: 500
|
||||
}
|
||||
]
|
||||
})))
|
||||
readonly property var results: enabled ? Search.rank(indexed, query.replace(/^\s*>/, ""), limit) : []
|
||||
}
|
||||
@@ -0,0 +1,449 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import "../components"
|
||||
import "../services"
|
||||
import "../theme"
|
||||
import "../core"
|
||||
|
||||
// Spotlight-style launcher: opens as a single search bar in the upper third.
|
||||
// Typing shows ranked results below it; the magnifying glass (or ↓ in an
|
||||
// empty bar) browses every application as an icon grid; > lists commands.
|
||||
// Runtime selects the concrete Wayland layer implementation.
|
||||
// qmllint disable uncreatable-type
|
||||
PanelWindow {
|
||||
// qmllint enable uncreatable-type
|
||||
id: root
|
||||
screen: ScreenService.current(ShellState.launcherScreen)
|
||||
anchors {
|
||||
top: true
|
||||
bottom: true
|
||||
left: true
|
||||
right: true
|
||||
}
|
||||
visible: ShellState.launcherOpen || panel.opacity > 0.01
|
||||
color: Theme.transparent
|
||||
exclusionMode: ExclusionMode.Ignore
|
||||
WlrLayershell.namespace: "glassMxrph-launcher"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: ShellState.launcherOpen ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||||
readonly property var options: ConfigService.ready ? ConfigService.data.launcher : ({
|
||||
width: 680,
|
||||
maxResults: 50,
|
||||
showDescriptions: true
|
||||
})
|
||||
readonly property string query: search.text.trim()
|
||||
readonly property bool commandMode: query.startsWith(">")
|
||||
property bool browsing: false
|
||||
readonly property bool showList: query !== ""
|
||||
readonly property bool showGrid: !showList && browsing
|
||||
readonly property var allApps: ApplicationsService.launchable.map(entry => ({
|
||||
id: entry.id,
|
||||
title: entry.name,
|
||||
description: entry.genericName || entry.comment || entry.id,
|
||||
entry: entry
|
||||
}))
|
||||
readonly property var results: showList ? (commandMode ? commands.results : apps.results) : showGrid ? allApps : []
|
||||
property int selectedIndex: 0
|
||||
property string launchError: ""
|
||||
readonly property real targetWidth: Math.min(options.width, root.width - 40)
|
||||
readonly property int barHeight: 60
|
||||
readonly property real maxBodyHeight: Math.min(460, root.height * 0.78 - barHeight - (root.height * 0.22))
|
||||
readonly property real bodyHeight: showList ? Math.min(maxBodyHeight, Math.max(84, list.contentHeight + 46 + (launchError ? 22 : 0))) : showGrid ? Math.min(maxBodyHeight, grid.contentHeight + 46) : 0
|
||||
readonly property int gridColumns: Math.max(1, Math.floor((targetWidth - 24) / 112))
|
||||
onResultsChanged: {
|
||||
selectedIndex = 0;
|
||||
list.contentY = 0;
|
||||
grid.contentY = 0;
|
||||
}
|
||||
function select(offset) {
|
||||
if (!results.length)
|
||||
return;
|
||||
selectedIndex = Math.max(0, Math.min(results.length - 1, selectedIndex + offset));
|
||||
if (showGrid)
|
||||
grid.positionViewAtIndex(selectedIndex, GridView.Contain);
|
||||
else
|
||||
list.positionViewAtIndex(selectedIndex, ListView.Contain);
|
||||
}
|
||||
function activate(index) {
|
||||
const result = results[index];
|
||||
if (!result)
|
||||
return;
|
||||
if (result.command) {
|
||||
ShellState.launcherOpen = false;
|
||||
CommandRegistry.execute(result.id);
|
||||
} else if (ApplicationsService.launch(result.entry, null))
|
||||
ShellState.launcherOpen = false;
|
||||
else
|
||||
launchError = ApplicationsService.error;
|
||||
}
|
||||
function toggleBrowse() {
|
||||
browsing = !browsing;
|
||||
if (browsing)
|
||||
search.clear();
|
||||
selectedIndex = 0;
|
||||
search.forceActiveFocus();
|
||||
}
|
||||
Component.onCompleted: LauncherState.window = root
|
||||
Component.onDestruction: LauncherState.window = null
|
||||
Connections {
|
||||
target: ShellState
|
||||
function onLauncherOpenChanged() {
|
||||
if (ShellState.launcherOpen) {
|
||||
search.text = "";
|
||||
root.browsing = false;
|
||||
root.launchError = "";
|
||||
root.selectedIndex = 0;
|
||||
Qt.callLater(() => search.forceActiveFocus());
|
||||
}
|
||||
}
|
||||
}
|
||||
AppSearch {
|
||||
id: apps
|
||||
enabled: ShellState.launcherOpen && root.showList && !root.commandMode
|
||||
query: search.text
|
||||
limit: root.options.maxResults
|
||||
}
|
||||
CommandSearch {
|
||||
id: commands
|
||||
enabled: ShellState.launcherOpen && root.commandMode
|
||||
query: search.text
|
||||
limit: root.options.maxResults
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: ShellState.launcherOpen = false
|
||||
}
|
||||
GlassPanel {
|
||||
id: panel
|
||||
objectName: "launcherSurface"
|
||||
x: Math.round((root.width - width) / 2)
|
||||
y: Math.round(root.height * 0.22)
|
||||
width: ShellState.launcherOpen ? root.targetWidth : Math.min(320, root.targetWidth)
|
||||
height: root.barHeight + root.bodyHeight
|
||||
radius: Math.min(Theme.radius + 6, root.barHeight / 2)
|
||||
opacity: ShellState.launcherOpen ? 1 : 0
|
||||
scale: ShellState.launcherOpen ? 1 : 1 - 0.04 * Theme.intensity
|
||||
clip: true
|
||||
Behavior on width {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
} // Consume inside clicks without dismissing.
|
||||
|
||||
// Search bar
|
||||
RowLayout {
|
||||
id: bar
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
height: root.barHeight
|
||||
anchors.leftMargin: 12
|
||||
anchors.rightMargin: 18
|
||||
spacing: 10
|
||||
Rectangle {
|
||||
objectName: "launcherBrowse"
|
||||
Layout.preferredWidth: 38
|
||||
Layout.preferredHeight: 38
|
||||
radius: 12
|
||||
color: root.browsing ? Theme.accent : browseArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: root.browsing ? "Hide applications" : "Show all applications"
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.duration / 2
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: root.commandMode ? ">" : Icons.available ? "" : "⌕"
|
||||
font.family: Icons.available && !root.commandMode ? Icons.family : ""
|
||||
color: root.browsing ? Theme.accentText : Theme.textSecondary
|
||||
font.pixelSize: 20
|
||||
}
|
||||
MouseArea {
|
||||
id: browseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.toggleBrowse()
|
||||
}
|
||||
ToolTip.visible: browseArea.containsMouse
|
||||
ToolTip.delay: 600
|
||||
ToolTip.text: root.browsing ? "Hide applications" : "All applications"
|
||||
}
|
||||
TextField {
|
||||
id: search
|
||||
objectName: "launcherSearch"
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 40
|
||||
placeholderText: root.browsing ? "Search applications" : "Spotlight Search"
|
||||
color: Theme.text
|
||||
placeholderTextColor: Theme.textSecondary
|
||||
selectByMouse: true
|
||||
font.pixelSize: 22
|
||||
font.weight: Font.Light
|
||||
background: Item {}
|
||||
padding: 0
|
||||
maximumLength: 256
|
||||
onTextEdited: root.launchError = ""
|
||||
Keys.onEscapePressed: {
|
||||
if (text !== "")
|
||||
clear();
|
||||
else if (root.browsing)
|
||||
root.browsing = false;
|
||||
else
|
||||
ShellState.launcherOpen = false;
|
||||
}
|
||||
Keys.onDownPressed: {
|
||||
if (!root.showList && !root.browsing)
|
||||
root.browsing = true;
|
||||
else
|
||||
root.select(root.showGrid ? root.gridColumns : 1);
|
||||
}
|
||||
Keys.onUpPressed: root.select(root.showGrid ? -root.gridColumns : -1)
|
||||
Keys.onRightPressed: event => {
|
||||
if (root.showGrid || event.modifiers & Qt.ControlModifier)
|
||||
root.select(1);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onLeftPressed: event => {
|
||||
if (root.showGrid || event.modifiers & Qt.ControlModifier)
|
||||
root.select(-1);
|
||||
else
|
||||
event.accepted = false;
|
||||
}
|
||||
Keys.onTabPressed: root.select(1)
|
||||
Keys.onBacktabPressed: root.select(-1)
|
||||
Keys.onReturnPressed: root.activate(root.selectedIndex)
|
||||
Keys.onEnterPressed: root.activate(root.selectedIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Results (typing) or the application grid (magnifying glass).
|
||||
Item {
|
||||
id: body
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: bar.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
visible: root.bodyHeight > 0 || panel.height > root.barHeight + 1
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.leftMargin: 14
|
||||
anchors.rightMargin: 14
|
||||
height: 1
|
||||
color: Theme.border
|
||||
}
|
||||
Text {
|
||||
id: section
|
||||
x: 22
|
||||
y: 12
|
||||
text: root.showGrid ? "Applications" : root.commandMode ? "Settings" : root.results.length ? "Top hits" : ""
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 11
|
||||
font.weight: Font.DemiBold
|
||||
}
|
||||
ListView {
|
||||
id: list
|
||||
objectName: "launcherResults"
|
||||
visible: root.showList
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 32
|
||||
anchors.leftMargin: 8
|
||||
anchors.rightMargin: 8
|
||||
anchors.bottomMargin: root.launchError ? 30 : 8
|
||||
clip: true
|
||||
model: root.showList ? root.results : []
|
||||
spacing: 2
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
delegate: Rectangle {
|
||||
id: resultRow
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property bool selected: root.selectedIndex === index
|
||||
width: list.width
|
||||
height: 46
|
||||
radius: 10
|
||||
color: selected ? Theme.accent : mouse.containsMouse ? Theme.hover : Theme.transparent
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 10
|
||||
anchors.rightMargin: 12
|
||||
spacing: 12
|
||||
Item {
|
||||
Layout.preferredWidth: 30
|
||||
Layout.preferredHeight: 30
|
||||
Image {
|
||||
id: icon
|
||||
anchors.fill: parent
|
||||
source: resultRow.modelData.entry ? ApplicationsService.icon(resultRow.modelData.entry) : ""
|
||||
sourceSize: Qt.size(60, 60)
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: icon.source.toString() === "" || icon.status === Image.Error
|
||||
text: resultRow.modelData.command ? "⚙" : resultRow.modelData.title.slice(0, 2).toUpperCase()
|
||||
color: resultRow.selected ? Theme.accentText : Theme.textSecondary
|
||||
font.pixelSize: 16
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: resultRow.modelData.title
|
||||
elide: Text.ElideRight
|
||||
color: resultRow.selected ? Theme.accentText : Theme.text
|
||||
font.pixelSize: 14
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
Text {
|
||||
visible: root.options.showDescriptions
|
||||
text: "— " + resultRow.modelData.description
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
color: resultRow.selected ? Qt.alpha(Theme.accentText, 0.75) : Theme.textSecondary
|
||||
font.pixelSize: 12
|
||||
}
|
||||
Item {
|
||||
visible: !root.options.showDescriptions
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Text {
|
||||
text: resultRow.modelData.command ? "Settings" : "Application"
|
||||
color: resultRow.selected ? Qt.alpha(Theme.accentText, 0.75) : Theme.textSecondary
|
||||
font.pixelSize: 11
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: mouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
// Hover highlights locally; only keys change keyboard selection.
|
||||
// Layout/scroll movement under a stationary pointer must not steal it.
|
||||
onClicked: root.activate(resultRow.index)
|
||||
}
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: modelData.title
|
||||
Accessible.onPressAction: root.activate(index)
|
||||
}
|
||||
}
|
||||
GridView {
|
||||
id: grid
|
||||
objectName: "launcherApps"
|
||||
visible: root.showGrid
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 32
|
||||
anchors.leftMargin: 12
|
||||
anchors.rightMargin: 12
|
||||
anchors.bottomMargin: 10
|
||||
clip: true
|
||||
model: root.showGrid ? root.results : []
|
||||
cellWidth: Math.floor(width / root.gridColumns)
|
||||
cellHeight: 100
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
delegate: Item {
|
||||
id: tile
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property bool selected: root.selectedIndex === index
|
||||
width: grid.cellWidth
|
||||
height: grid.cellHeight
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 4
|
||||
radius: 14
|
||||
color: tile.selected ? Qt.alpha(Theme.accent, 0.35) : tileArea.containsMouse ? Theme.hover : Theme.transparent
|
||||
border.width: tile.selected ? 1 : 0
|
||||
border.color: Theme.accentVivid
|
||||
}
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: 6
|
||||
Image {
|
||||
id: tileIcon
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: 52
|
||||
height: 52
|
||||
source: ApplicationsService.icon(tile.modelData.entry)
|
||||
sourceSize: Qt.size(104, 104)
|
||||
fillMode: Image.PreserveAspectFit
|
||||
asynchronous: true
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: tileIcon.source.toString() === "" || tileIcon.status === Image.Error
|
||||
text: tile.modelData.title.slice(0, 2).toUpperCase()
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 18
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: grid.cellWidth - 12
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: tile.modelData.title
|
||||
elide: Text.ElideRight
|
||||
color: Theme.text
|
||||
font.pixelSize: 11
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: tileArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onClicked: root.activate(tile.index)
|
||||
}
|
||||
Accessible.role: Accessible.Button
|
||||
Accessible.name: modelData.title
|
||||
Accessible.onPressAction: root.activate(index)
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: 12
|
||||
visible: root.showList && root.results.length === 0
|
||||
text: root.commandMode ? "No matching settings" : "No results"
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 13
|
||||
}
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.margins: 12
|
||||
visible: !!root.launchError
|
||||
elide: Text.ElideRight
|
||||
text: root.launchError
|
||||
color: Theme.urgent
|
||||
font.pixelSize: 12
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "../core"
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
property var window: null
|
||||
IpcHandler {
|
||||
target: "launcher"
|
||||
function toggle(): void {
|
||||
ShellState.toggleLauncher();
|
||||
}
|
||||
function open(): void {
|
||||
ShellState.openLauncher();
|
||||
}
|
||||
function close(): void {
|
||||
ShellState.launcherOpen = false;
|
||||
}
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
opened: ShellState.launcherOpen,
|
||||
screen: root.window && root.window.screen ? root.window.screen.name : "",
|
||||
ready: !!root.window
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Pure ranking logic shared by application and command search. No process execution.
|
||||
function normalize(text) {
|
||||
return String(text || "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim();
|
||||
}
|
||||
function score(text, needle) {
|
||||
if (!needle) return 0;
|
||||
if (text === needle) return 10000;
|
||||
if (text.startsWith(needle)) return 8000 - Math.min(text.length, 500);
|
||||
const inside = text.indexOf(needle);
|
||||
if (inside >= 0) return 6000 - inside * 4 - Math.min(text.length, 500);
|
||||
let cursor = 0, previous = -1, value = 1000;
|
||||
for (const letter of needle) {
|
||||
const index = text.indexOf(letter, cursor);
|
||||
if (index < 0) return -Infinity;
|
||||
value += index === previous + 1 ? 30 : 0;
|
||||
if (index === 0 || /[\s._/-]/.test(text[index - 1])) value += 45;
|
||||
value -= index - cursor;
|
||||
previous = index; cursor = index + 1;
|
||||
}
|
||||
return value - Math.min(text.length, 500);
|
||||
}
|
||||
function index(items) {
|
||||
return items.map(item => ({item:item,fields:item.fields.map(field => ({text:normalize(field.text),penalty:field.penalty || 0}))}));
|
||||
}
|
||||
function rank(indexed, query, limit) {
|
||||
const tokens = normalize(query).split(/\s+/).filter(Boolean);
|
||||
const matches = [];
|
||||
for (const row of indexed) {
|
||||
let total = 0;
|
||||
for (const token of tokens) {
|
||||
const best = Math.max(...row.fields.map(field => score(field.text,token) - field.penalty));
|
||||
if (!Number.isFinite(best)) {total=-Infinity;break;}
|
||||
total += best;
|
||||
}
|
||||
if (Number.isFinite(total)) matches.push({item:row.item,score:total});
|
||||
}
|
||||
matches.sort((a,b) => b.score-a.score || a.item.title.localeCompare(b.item.title) || a.item.id.localeCompare(b.item.id));
|
||||
return matches.slice(0,limit).map(row => row.item);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
singleton CommandRegistry 1.0 CommandRegistry.qml
|
||||
singleton LauncherState 1.0 LauncherState.qml
|
||||
AppSearch 1.0 AppSearch.qml
|
||||
CommandSearch 1.0 CommandSearch.qml
|
||||
Launcher 1.0 Launcher.qml
|
||||
Reference in new issue
Block a user