Skip to content

Commit ae53e36

Browse files
committed
统一代码顺序
1 parent 5a47ed8 commit ae53e36

6 files changed

Lines changed: 132 additions & 126 deletions

File tree

app/src/config/appearance.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ import {updateHotkeyTip} from "../protyle/util/compatibility";
1616
import {Menu} from "../plugin/Menu";
1717
import {escapeAttr} from "../util/escape";
1818
import {
19-
buttonRow,
20-
customRow,
21-
findSettingRowByControlId,
22-
rangeRow,
19+
type SettingBindApi,
20+
type SettingSection,
21+
switchRow,
2322
numberRow,
23+
rangeRow,
2424
selectRow,
25+
buttonRow,
26+
customRow,
2527
stackRow,
26-
switchRow,
27-
type SettingBindApi,
28-
type SettingSection,
28+
findSettingRowByControlId,
2929
} from "./ui/settingRows";
3030
import {filterSettingSections} from "./ui/search";
3131
import {renderSettingTabHtmlFromSections, renderSwitchRow} from "./ui/render";

app/src/config/editor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {updateHotkeyTip} from "../protyle/util/compatibility";
22
import {Constants} from "../constants";
33
import {
4+
type SettingBindApi,
5+
type SettingSection,
6+
switchRow,
7+
textRow,
48
textBlockRow,
5-
customRow,
6-
findSettingRowByControlId,
79
numberRow,
810
rangeRow,
911
selectRow,
10-
switchRow,
11-
textRow,
12-
type SettingBindApi,
13-
type SettingSection,
12+
customRow,
13+
findSettingRowByControlId,
1414
} from "./ui/settingRows";
1515
import {filterSettingSections} from "./ui/search";
1616
import {renderSettingTabHtmlFromSections, renderSwitchRow} from "./ui/render";

app/src/config/file.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {confirmDialog} from "../dialog/confirmDialog";
22
import {genNotebookOption} from "../menus/onGetnotebookconf";
33
import {fetchPost} from "../util/fetch";
44
import {
5-
findSettingRowByControlId,
6-
notebookSavePathRow,
5+
type SettingSection,
6+
switchRow,
77
numberRow,
88
stackRow,
9-
switchRow,
10-
type SettingSection,
9+
notebookSavePathRow,
10+
findSettingRowByControlId,
1111
} from "./ui/settingRows";
1212
import {filterSettingSections} from "./ui/search";
1313
import {renderSettingTabHtmlFromSections} from "./ui/render";

app/src/config/ui/render.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,15 @@ const renderStack = (entry: SettingRowStack): string => {
200200
const renderRow = (row: SettingRow): string => {
201201
const cfg = window.siyuan.config;
202202
switch (row.type) {
203-
case "custom":
204-
return row.html();
205-
case "stack":
206-
return renderStack(row);
207203
case "switch":
208204
return renderSwitchRow(row.id, row.title, row.desc, getSwitchChecked(row.id));
209-
case "range": {
210-
const v = getAtPath(cfg, row.id);
211-
const num = typeof v === "number" && !Number.isNaN(v) ? v : row.min;
212-
return renderRangeRow(
213-
row.id,
214-
row.title,
215-
row.desc,
216-
row.min,
217-
row.max,
218-
row.step,
219-
num
220-
);
205+
case "text": {
206+
const val = getAtPath(cfg, row.id);
207+
const str = typeof val === "string" ? val : "";
208+
return renderTextRow(row.id, row.title, row.desc, str);
221209
}
210+
case "textBlock":
211+
return renderTextBlockRow(row.title, row.desc, row.id, row.getTextValue());
222212
case "number": {
223213
const raw = getAtPath(cfg, row.id);
224214
const value = typeof raw === "number" && !Number.isNaN(raw) ? raw : 0;
@@ -232,8 +222,19 @@ const renderRow = (row: SettingRow): string => {
232222
row.unit
233223
);
234224
}
235-
case "button":
236-
return renderButtonRow(row.id, row.title, row.desc, row.label, row.icon);
225+
case "range": {
226+
const v = getAtPath(cfg, row.id);
227+
const num = typeof v === "number" && !Number.isNaN(v) ? v : row.min;
228+
return renderRangeRow(
229+
row.id,
230+
row.title,
231+
row.desc,
232+
row.min,
233+
row.max,
234+
row.step,
235+
num
236+
);
237+
}
237238
case "select": {
238239
const firstVal = row.options[0]?.value;
239240
const numericSelect = row.options.length > 0 && typeof firstVal === "number";
@@ -255,11 +256,12 @@ const renderRow = (row: SettingRow): string => {
255256
}
256257
return renderSelectRow(row.id, row.title, row.desc, row.options, current);
257258
}
258-
case "text": {
259-
const val = getAtPath(cfg, row.id);
260-
const str = typeof val === "string" ? val : "";
261-
return renderTextRow(row.id, row.title, row.desc, str);
262-
}
259+
case "button":
260+
return renderButtonRow(row.id, row.title, row.desc, row.label, row.icon);
261+
case "custom":
262+
return row.html();
263+
case "stack":
264+
return renderStack(row);
263265
case "notebookSavePath":
264266
return renderNotebookSavePathRow(
265267
row.title,
@@ -268,8 +270,6 @@ const renderRow = (row: SettingRow): string => {
268270
row.pathId,
269271
row.getOptionsHtml()
270272
);
271-
case "textBlock":
272-
return renderTextBlockRow(row.title, row.desc, row.id, row.getTextValue());
273273
}
274274
};
275275

app/src/config/ui/search.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ export const textMatchesConfigSearch = (text: string, queryLower: string): boole
3030
/** 行是否命中设置面板搜索(工厂行看 `title` / `desc`;`custom` 看 `keywords`;`stack` 由各行左列与右侧控件文案推导;`select` 另含选项文案) */
3131
export const configRowMatchesSearchQuery = (row: SettingRow, queryLower: string): boolean => {
3232
switch (row.type) {
33-
case "custom":
34-
return row.keywords.some((k) => textMatchesConfigSearch(k, queryLower));
35-
case "stack":
36-
return stackExtraSearchStrings(row).some((s) => textMatchesConfigSearch(s, queryLower));
37-
case "select":
38-
if (
33+
case "switch":
34+
case "text":
35+
case "textBlock":
36+
case "range":
37+
case "notebookSavePath":
38+
return (
3939
textMatchesConfigSearch(row.title, queryLower) ||
4040
textMatchesConfigSearch(row.desc, queryLower)
41-
) {
42-
return true;
43-
}
44-
return row.options.some((o) => textMatchesConfigSearch(o.label, queryLower));
41+
);
4542
case "number":
4643
if (
4744
textMatchesConfigSearch(row.title, queryLower) ||
@@ -53,41 +50,49 @@ export const configRowMatchesSearchQuery = (row: SettingRow, queryLower: string)
5350
return true;
5451
}
5552
return false;
56-
case "button":
57-
return (
58-
textMatchesConfigSearch(row.title, queryLower) ||
59-
textMatchesConfigSearch(row.desc, queryLower) ||
60-
textMatchesConfigSearch(row.label, queryLower)
61-
);
62-
default:
53+
case "select":
6354
if (
6455
textMatchesConfigSearch(row.title, queryLower) ||
6556
textMatchesConfigSearch(row.desc, queryLower)
6657
) {
6758
return true;
6859
}
69-
return false;
60+
return row.options.some((o) => textMatchesConfigSearch(o.label, queryLower));
61+
case "button":
62+
return (
63+
textMatchesConfigSearch(row.title, queryLower) ||
64+
textMatchesConfigSearch(row.desc, queryLower) ||
65+
textMatchesConfigSearch(row.label, queryLower)
66+
);
67+
case "custom":
68+
return row.keywords.some((k) => textMatchesConfigSearch(k, queryLower));
69+
case "stack":
70+
return stackExtraSearchStrings(row).some((s) => textMatchesConfigSearch(s, queryLower));
7071
}
7172
};
7273

7374
/** 从一行注册数据取出参与侧栏与内容区检索索引的字符串(`custom` 仅用 `keywords`;`stack` 由各行推导;其余含 `title` / `desc` 的行用二者) */
7475
export const collectRowStringsForSearchIndex = (row: SettingRow): string[] => {
7576
switch (row.type) {
76-
case "custom":
77-
return [...row.keywords];
78-
case "stack":
79-
return stackExtraSearchStrings(row);
80-
case "select":
81-
return [row.title, row.desc, ...row.options.map((o) => o.label)];
77+
case "switch":
78+
case "text":
79+
case "textBlock":
80+
case "range":
81+
case "notebookSavePath":
82+
return [row.title, row.desc];
8283
case "number":
8384
if (row.unit) {
8485
return [row.title, row.desc, row.unit];
8586
}
8687
return [row.title, row.desc];
88+
case "select":
89+
return [row.title, row.desc, ...row.options.map((o) => o.label)];
8790
case "button":
8891
return [row.title, row.desc, row.label];
89-
default:
90-
return [row.title, row.desc];
92+
case "custom":
93+
return [...row.keywords];
94+
case "stack":
95+
return stackExtraSearchStrings(row);
9196
}
9297
};
9398

0 commit comments

Comments
 (0)