mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
a27b26abbd
The shortcut contract (shortcutActions.ts + shortcutTypes.ts) is NOT a
pure-frontend file: src-tauri/src/cli/parse.rs include_str!s
'/../src/config/shortcutActions.ts' at compile time, so moving it to
lib/shortcuts/ (slice 7ad19671) broke the Rust build (couldn't read the file ->
dev build won't start). Revert the contract back to src/config/ — it has a
build-time backend path contract and belongs where Rust anchors it, not in lib/.
No Rust file touched (fix = restore the frontend path the backend expects).
cargo check green (13s), tsc 0, lint 0/0, frontend suite 319/2353 green.
Lesson: grep src-tauri for include_str!/include_bytes! '../src/...' before
moving ANY frontend file — Rust can pin a TS file by path.
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import type { TFunction } from 'i18next';
|
|
import { GLOBAL_SHORTCUT_ACTIONS, IN_APP_SHORTCUT_ACTIONS } from '@/config/shortcutActions';
|
|
import { SETTINGS_INDEX, matchScore, type Tab } from '@/features/settings/components/settingsTabs';
|
|
|
|
export type SettingsSearchHit = {
|
|
tab: Tab;
|
|
title: string;
|
|
focusTitle: string;
|
|
score: number;
|
|
key: string;
|
|
};
|
|
|
|
export function searchSettings(query: string, activeTab: Tab, t: TFunction): SettingsSearchHit[] {
|
|
const q = query.trim();
|
|
if (!q) return [];
|
|
|
|
const hits: SettingsSearchHit[] = [];
|
|
|
|
for (const entry of SETTINGS_INDEX) {
|
|
const title = t(entry.titleKey);
|
|
const hay = entry.keywords ? `${title} ${entry.keywords}` : title;
|
|
const score = matchScore(hay, q);
|
|
if (score <= 0) continue;
|
|
const focusTitle = entry.focusTitleKey ? t(entry.focusTitleKey) : title;
|
|
hits.push({ tab: entry.tab, title, focusTitle, score, key: entry.titleKey });
|
|
}
|
|
|
|
const inAppSection = t('settings.inputKeybindingsTitle');
|
|
for (const { id, getLabel } of IN_APP_SHORTCUT_ACTIONS) {
|
|
const title = getLabel(t);
|
|
const hay = `${title} ${inAppSection} shortcut hotkey keyboard in-app ${id.replace(/-/g, ' ')}`;
|
|
const score = matchScore(hay, q);
|
|
if (score <= 0) continue;
|
|
hits.push({ tab: 'input', title, focusTitle: inAppSection, score, key: `in-app:${id}` });
|
|
}
|
|
|
|
const globalSection = t('settings.globalShortcutsTitle');
|
|
for (const { id, getLabel } of GLOBAL_SHORTCUT_ACTIONS) {
|
|
const title = getLabel(t);
|
|
const hay = `${title} ${globalSection} shortcut hotkey global media ${id.replace(/-/g, ' ')}`;
|
|
const score = matchScore(hay, q);
|
|
if (score <= 0) continue;
|
|
hits.push({ tab: 'input', title, focusTitle: globalSection, score, key: `global:${id}` });
|
|
}
|
|
|
|
hits.sort((a, b) => {
|
|
const aCurrent = a.tab === activeTab ? 1 : 0;
|
|
const bCurrent = b.tab === activeTab ? 1 : 0;
|
|
if (aCurrent !== bCurrent) return bCurrent - aCurrent;
|
|
return b.score - a.score;
|
|
});
|
|
|
|
return hits;
|
|
}
|