From 374215148a08f75f84adf730187986735b18c45b Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 5 Aug 2025 18:05:18 +0800 Subject: perf(launcher:selection): if check instead of function clamp --- launcher/Launcher.qml | 23 ++++------------------- launcher/components/SelectionState.qml | 9 ++++----- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/launcher/Launcher.qml b/launcher/Launcher.qml index 9b49699..7577139 100644 --- a/launcher/Launcher.qml +++ b/launcher/Launcher.qml @@ -358,15 +358,6 @@ ILauncher { let set = 0; - // normalize to keep selectedPriority within bounds - function clampPriority() { - const max = Math.max(0, SelectionState.priorities.length - 1); - if (SelectionState.selectedPriority < 0) - SelectionState.selectedPriority = max; - else if (SelectionState.selectedPriority > max) - SelectionState.selectedPriority = 0; - } - switch (direction) { case 1: if (item.prev()) @@ -388,21 +379,15 @@ ILauncher { switch (set) { case 1: - SelectionState.selectedPriority++; - clampPriority(); + if (SelectionState.selectedPriority < SelectionState.priorities.length - 1) + SelectionState.selectedPriority++; break; case -1: - SelectionState.selectedPriority--; - clampPriority(); + if (SelectionState.selectedPriority > 0) + SelectionState.selectedPriority--; break; } - // try focus handoff to the new item if it exposes focus/select API - const newItem = SelectionState?.priorities[SelectionState.selectedPriority] || null; - if (newItem && newItem.focus) - newItem.focus(); - - // sync selection rectangle after priority change selectionSync.running = true; } diff --git a/launcher/components/SelectionState.qml b/launcher/components/SelectionState.qml index d945d70..2e53155 100644 --- a/launcher/components/SelectionState.qml +++ b/launcher/components/SelectionState.qml @@ -12,13 +12,12 @@ Singleton { // order them based on widgets(which came from order from config) onPrioritiesChanged: { - // priorities = priorities.filter(item => item.priority === true); // bind loop - // dunno y ts works w/o triggering a binding loop but okay.. - for (let i = 0; i < priorities.length; i++) - if (priorities[i].priority !== true) + for (let i = priorities.length - 1; i >= 0; i--) + if (!priorities[i] || priorities[i].priority !== true) priorities.splice(i, 1); - priorities.sort((a, b) => widgets.indexOf(a) - widgets.indexOf(b)); + priorities.sort((a, b) => (widgets.indexOf(a) - widgets.indexOf(b)) || 0); + priorities.forEach((item, index) => {}); } -- cgit v1.2.3