1- import { Constants } from "../constants" ;
21import type { TConfigTab } from "./types" ;
32import { getConfigTabDefs } from "./tabs" ;
4- import { collectSettingTabSearchStrings } from "./ui/search" ;
3+ import { collectSettingTabSearchStrings , textMatchesConfigSearch } from "./ui/search" ;
54import { buildEditorSections , editorSettings } from "./editor" ;
65import { buildFileSections , fileSettings } from "./file" ;
76import { buildAppearanceSections , appearanceSettings } from "./appearance" ;
87import { buildFlashcardSections , flashcardSettings } from "./flashcard" ;
98import { buildAiSections , aiSettings } from "./ai" ;
109import { buildExportSections , exportSettings } from "./export" ;
1110import { buildSearchSections , searchSettings } from "./searchSettings" ;
11+ import { buildKeymapSections , keymapSettings } from "./keymap" ;
1212import { mountConfigTab } from "./mountConfigTab" ;
13- import { keymap } from "./keymap" ;
1413import { App } from "../index" ;
1514import { isPhablet } from "../protyle/util/compatibility" ;
1615
@@ -189,7 +188,7 @@ const applySettingPanelSearch = (panelElement: HTMLElement, query: string) => {
189188 }
190189} ;
191190
192- type TConfigTabLangKeys = Exclude < TConfigTab , "editor" | "file" | "appearance" | "flashcard" | "ai" | "export" | "search" > ;
191+ type TConfigTabLangKeys = Exclude < TConfigTab , "editor" | "file" | "appearance" | "flashcard" | "ai" | "export" | "search" | "keymap" > ;
193192
194193/**
195194 * 侧栏标签索引关键词:按一级 Tab 的 `id` 与 `TAB_LANG_KEYS` 的键对应;
@@ -204,13 +203,6 @@ const TAB_LANG_KEYS: Record<TConfigTabLangKeys, string[]> = {
204203 assets : [
205204 "assets" , "unreferencedAssets" , "unreferencedAV" , "missingAssets" , "delete" , "clearAll" , "clearAllAV" , "emptyContent" ,
206205 ] ,
207- keymap : [ "keymap" , "keymapTip" , "keymapTip2" , "refresh" , "reset" , "clear" , "search" , "general" , "editor" , "element" , "headings" , "list1" ,
208- "plugin" ] . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . general ) )
209- . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . editor . general ) )
210- . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . editor . heading ) )
211- . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . editor . insert ) )
212- . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . editor . list ) )
213- . concat ( Object . keys ( Constants . SIYUAN_KEYMAP . editor . table ) ) ,
214206 sync : [
215207 "configGroupAccountSync" , "configGroupAccount" , "configGroupSync" , "configGroupLocalDataRepo" ,
216208 "cloudStorage" , "trafficStat" , "sync" , "backup" , "cdn" , "total" , "sizeLimit" , "pointExchangeSize" ,
@@ -269,6 +261,8 @@ const getTabSearchStrings = (tabId: TConfigTab): string[] => {
269261 return collectSettingTabSearchStrings ( window . siyuan . languages . export , buildExportSections ( ) ) ;
270262 case "search" :
271263 return collectSettingTabSearchStrings ( window . siyuan . languages . search , buildSearchSections ( ) ) ;
264+ case "keymap" :
265+ return collectSettingTabSearchStrings ( window . siyuan . languages . keymap , buildKeymapSections ( ) ) ;
272266 }
273267 return getLang ( TAB_LANG_KEYS [ tabId ] ) ;
274268} ;
@@ -300,8 +294,7 @@ export const initConfigSearch = (element: HTMLElement, app: App) => {
300294 }
301295 // TODO 在把所有设置项都改成注册式之后,把 .toLowerCase() 移到对应的收集文案的函数里只处理一次,而不是在这里反复处理
302296 // TODO 预先将含 HTML 的文案转为纯文本(比如 innerText 或 textContent),避免命中 HTML 标签中的文本(例如搜索 "code" 会命中包含 <code> 标签的文案)
303- const subLower = subItem . toLowerCase ( ) ;
304- if ( subLower . indexOf ( keywords ) > - 1 ) {
297+ if ( textMatchesConfigSearch ( subItem , keywords ) ) {
305298 matchedTabIds . add ( id ) ;
306299 break ;
307300 }
@@ -393,6 +386,9 @@ export const switchConfigTab = (dialogElement: HTMLElement, app: App, type: TCon
393386 case "search" :
394387 void searchSettings . mount ( el , keywords ) ;
395388 return ;
389+ case "keymap" :
390+ void keymapSettings . mount ( el , keywords ) ;
391+ return ;
396392 }
397393 }
398394
@@ -402,14 +398,6 @@ export const switchConfigTab = (dialogElement: HTMLElement, app: App, type: TCon
402398 if ( ! keywords ) {
403399 return ;
404400 }
405- if ( type === "keymap" ) {
406- const searchElement = keymap . element . querySelector ( "#keymapInput" ) as HTMLInputElement ;
407- const searchKeymapElement = keymap . element . querySelector ( "#searchByKey" ) as HTMLInputElement ;
408- searchElement . value = keywords ;
409- searchKeymapElement . value = "" ;
410- keymap . search ( searchElement . value , searchKeymapElement . value ) ;
411- return ;
412- }
413401 applySettingPanelSearch ( containerElement , keywords ) ;
414402} ;
415403
@@ -451,17 +439,9 @@ const restoreConfigTabs = (dialogElement: HTMLElement, app: App) => {
451439 case "search" :
452440 void searchSettings . mount ( container as HTMLElement ) ;
453441 break ;
454- case "keymap" : {
455- keymap . element = container ;
456- const searchElement = container . querySelector ( "#keymapInput" ) as HTMLInputElement | null ;
457- const searchKeymapElement = container . querySelector ( "#searchByKey" ) as HTMLInputElement | null ;
458- if ( searchElement && searchKeymapElement ) {
459- searchElement . value = "" ;
460- searchKeymapElement . value = "" ;
461- keymap . search ( "" , "" ) ;
462- }
442+ case "keymap" :
443+ void keymapSettings . mount ( container as HTMLElement ) ;
463444 break ;
464- }
465445 default :
466446 applySettingPanelSearch ( container , "" ) ;
467447 break ;
0 commit comments