Skip to content

Commit ea7352d

Browse files
committed
feat: mod 选项搜索
1 parent 8d7f796 commit ea7352d

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

MaiChartManager/Front/src/components/ModManager/AquaMaiConfigurator.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import _ from "lodash";
77
import { KeyCodeName } from "@/components/ModManager/types/KeyCodeName";
88
import ProblemsDisplay from "@/components/ProblemsDisplay";
99
import configSort from './configSort.yaml'
10+
import { useMagicKeys, whenever } from "@vueuse/core";
1011

1112
const sectionPanelOverrides = import.meta.glob('./sectionPanelOverride/*/index.tsx', { eager: true })
1213
const getSectionPanelOverride = (path: string) => {
@@ -101,31 +102,56 @@ export default defineComponent({
101102
useNewSort: { type: Boolean, default: false },
102103
},
103104
setup(props, { emit }) {
105+
const search = ref('');
106+
const searchRef = ref();
107+
108+
const { ctrl_f } = useMagicKeys({
109+
passive: false,
110+
onEventFired(e) {
111+
if (e.ctrlKey && e.key === 'f' && e.type === 'keydown')
112+
e.preventDefault()
113+
},
114+
})
115+
whenever(ctrl_f, () => searchRef.value?.select());
116+
117+
const filteredSections = computed(() => {
118+
if (!search.value) return props.config.sections;
119+
const s = search.value.toLowerCase();
120+
return props.config.sections?.filter(it =>
121+
it.path?.toLowerCase().includes(s) ||
122+
it.attribute?.comment?.commentZh?.toLowerCase().includes(s) ||
123+
it.attribute?.comment?.commentEn?.toLowerCase().includes(s) ||
124+
it.entries?.some(entry => entry.name?.toLowerCase().includes(s) || entry.path?.toLowerCase().includes(s) ||
125+
entry.attribute?.comment?.commentZh?.toLowerCase().includes(s) || entry.attribute?.comment?.commentEn?.toLowerCase().includes(s))
126+
);
127+
})
128+
104129
const bigSections = computed(() => {
105130
if (props.useNewSort) {
106-
return Object.keys(configSort)
131+
return Object.keys(configSort).filter(it => filteredSections.value!.some(s => configSort[it].includes(s.path!)));
107132
}
108-
return _.uniq(props.config.sections!.filter(it => !it.attribute?.exampleHidden).map(s => s.path?.split('.')[0]));
133+
return _.uniq(filteredSections.value!.filter(it => !it.attribute?.exampleHidden).map(s => s.path?.split('.')[0]));
109134
});
110135

111136
const otherSection = computed(() => {
112137
if (!props.useNewSort) return [];
113138
const knownSections = _.flatten(Object.values(configSort) as string[][]);
114-
return props.config.sections?.filter(it => !knownSections.includes(it.path!) && !it.attribute!.exampleHidden) || [];
139+
return filteredSections.value?.filter(it => !knownSections.includes(it.path!) && !it.attribute!.exampleHidden) || [];
115140
});
116141

117142
return () => <div class="grid cols-[14em_auto]">
118143
<NAnchor type="block" offsetTarget="#scroll">
119144
{bigSections.value.map((key) => <NAnchorLink key={key} title={key} href={`#${key}`}/>)}
120145
{otherSection.value.length > 0 && <NAnchorLink key="其他" title="其他" href="#其他"/>}
121146
</NAnchor>
122-
<NScrollbar class="max-h-75vh p-2"
147+
<NScrollbar class="h-75vh p-2 relative"
123148
// @ts-ignore
124149
id="scroll"
125150
>
151+
<NInput v-model:value={search.value} placeholder="搜索" size="small" clearable class="sticky top-0 z-200" ref={searchRef}/>
126152
{bigSections.value.map((big) => <div id={big} key={big}>
127153
<NDivider titlePlacement="left" class="mt-2!">{big}</NDivider>
128-
{props.config.sections?.filter(it => {
154+
{filteredSections.value?.filter(it => {
129155
if (props.useNewSort) {
130156
return configSort[big!].includes(it.path!);
131157
}

MaiChartManager/Front/src/components/ModManager/ConfigEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineComponent({
2828
const installingMelonLoader = ref(false)
2929
const installingAquaMai = ref(false)
3030
const showAquaMaiInstallDone = ref(false)
31-
const useNewSort = useStorage('useNewSort', false)
31+
const useNewSort = useStorage('useNewSort', true)
3232

3333
const updateAquaMaiConfig = async () => {
3434
try {

0 commit comments

Comments
 (0)