@@ -7,6 +7,7 @@ import _ from "lodash";
77import { KeyCodeName } from "@/components/ModManager/types/KeyCodeName" ;
88import ProblemsDisplay from "@/components/ProblemsDisplay" ;
99import configSort from './configSort.yaml'
10+ import { useMagicKeys , whenever } from "@vueuse/core" ;
1011
1112const sectionPanelOverrides = import . meta. glob ( './sectionPanelOverride/*/index.tsx' , { eager : true } )
1213const 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 }
0 commit comments