Skip to content

Commit 64bc2a5

Browse files
committed
重构为注册式设置、重新实现搜索功能:设置 - 快捷键(未完成)
1 parent b3d02a1 commit 64bc2a5

5 files changed

Lines changed: 24 additions & 41 deletions

File tree

app/src/config/mountConfigTab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {aiSettings} from "./ai";
88
import {exportSettings} from "./export";
99
import {searchSettings} from "./searchSettings";
1010
import {assets} from "./assets";
11-
import {keymap} from "./keymap";
11+
import {keymapSettings} from "./keymap";
1212
import {bazaar} from "./bazaar";
1313
import {sync} from "./sync";
1414
import {access} from "./access";
@@ -51,9 +51,7 @@ export const mountConfigTab = (type: TConfigTab, containerElement: Element, app:
5151
void searchSettings.mount(containerElement as HTMLElement);
5252
break;
5353
case "keymap":
54-
keymap.element = containerElement;
55-
containerElement.innerHTML = keymap.genHTML(app);
56-
keymap.bindEvent(app);
54+
void keymapSettings.mount(containerElement as HTMLElement);
5755
break;
5856
case "sync":
5957
sync.element = containerElement;

app/src/config/search.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import {Constants} from "../constants";
21
import type {TConfigTab} from "./types";
32
import {getConfigTabDefs} from "./tabs";
4-
import {collectSettingTabSearchStrings} from "./ui/search";
3+
import {collectSettingTabSearchStrings, textMatchesConfigSearch} from "./ui/search";
54
import {buildEditorSections, editorSettings} from "./editor";
65
import {buildFileSections, fileSettings} from "./file";
76
import {buildAppearanceSections, appearanceSettings} from "./appearance";
87
import {buildFlashcardSections, flashcardSettings} from "./flashcard";
98
import {buildAiSections, aiSettings} from "./ai";
109
import {buildExportSections, exportSettings} from "./export";
1110
import {buildSearchSections, searchSettings} from "./searchSettings";
11+
import {buildKeymapSections, keymapSettings} from "./keymap";
1212
import {mountConfigTab} from "./mountConfigTab";
13-
import {keymap} from "./keymap";
1413
import {App} from "../index";
1514
import {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;

app/src/config/ui/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const renderButtonRow = (row: Pick<SettingRowButton, "id" | "title" | "desc" | "
104104
return `<div class="fn__flex b3-label config__item">
105105
<div class="fn__flex-1">
106106
${title}
107-
<div class="b3-label__text">${desc}</div>
107+
${desc ? `<div class="b3-label__text">${desc}</div>` : ""}
108108
</div>
109109
<span class="fn__space"></span>
110110
${buildButtonHtml(id, label, icon)}

app/src/config/ui/search.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export const configRowMatchesSearchQuery = (row: SettingRow, queryLower: string)
7777
case "button":
7878
return (
7979
textMatchesConfigSearch(row.title, queryLower) ||
80-
textMatchesConfigSearch(row.desc, queryLower) ||
81-
textMatchesConfigSearch(row.label, queryLower)
80+
textMatchesConfigSearch(row.label, queryLower) ||
81+
(row.desc ? textMatchesConfigSearch(row.desc, queryLower) : false)
8282
);
8383
case "custom":
8484
return row.keywords.some((k) => textMatchesConfigSearch(k, queryLower));
@@ -106,8 +106,13 @@ export const collectRowStringsForSearchIndex = (row: SettingRow): string[] => {
106106
return [row.title, row.desc];
107107
case "select":
108108
return [row.title, row.desc, ...row.options.map((o) => o.label ?? String(o.value))];
109-
case "button":
110-
return [row.title, row.desc, row.label];
109+
case "button": {
110+
const out = [row.title, row.label];
111+
if (row.desc) {
112+
out.push(row.desc);
113+
}
114+
return out;
115+
}
111116
case "custom":
112117
return [...row.keywords];
113118
case "switchQuery":

app/src/config/ui/settingRows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface SettingRowButton {
7777
type: "button";
7878
id: string;
7979
title: string;
80-
desc: string;
80+
desc?: string;
8181
label: string;
8282
icon: string;
8383
bind: (root: HTMLElement) => void | Promise<void>;

0 commit comments

Comments
 (0)